With the Ignite UI for Web Components Select feature in Web Components Grid you can easily interact with and manipulate data using simple mouse interactions. There are three selection modes available:
The sample below demonstrates three types of cell selection behaviors in the IgcGridComponent. Use the buttons below to enable each of the available selection modes.
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png" ><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample ig-typography"><divclass="options vertical"><igc-property-editor-panelname="PropertyEditor"id="PropertyEditor"description-type="WebGrid"is-horizontal="true"is-wrapping-enabled="true"><igc-property-editor-property-descriptionproperty-path="CellSelection"name="CellSelectionEditor"id="CellSelectionEditor"value-type="EnumValue"drop-down-names="None, Single, Multiple"drop-down-values="NOne, Single, Multiple"></igc-property-editor-property-description></igc-property-editor-panel></div><divclass="container fill"><igc-gridauto-generate="false"name="grid"id="grid"><igc-columnfield="ProductID"header="Product ID"></igc-column><igc-columnfield="ProductName"header="Product Name"></igc-column><igc-columnfield="UnitsInStock"header="Units In Stock"data-type="number"></igc-column><igc-columnfield="UnitPrice"header="Units Price"data-type="number"></igc-column><igc-columnfield="Discontinued"data-type="boolean"></igc-column><igc-columnfield="OrderDate"header="Order Date"data-type="date"></igc-column></igc-grid></div></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %><scriptsrc="src/index.ts"></script><% } %>
</body></html>html
/* shared styles are loaded from: *//* https://static.infragistics.com/xplatform/css/samples */css
Like this sample? Get access to our complete Ignite UI for Web Components toolkit and start building your own apps in minutes. Download it for free.
Property rowSelection enables you to specify the following options:
None - Row selection would be disabled for the IgcGridComponent.
Single - Selection of only one row within the IgcGridComponent would be available.
Multiple - Multi-row selection would be available by using the row selectors, with a key combination like ctrl + click, or by pressing the space key once a cell is focused.
Property cellSelection enables you to specify the following options:
None - Cell selection would be disabled for the IgcGridComponent.
Single - Selection of only one cell within the IgcGridComponent would be available.
Multiple - Currently, this is the default state of the selection in the IgcGridComponent. Multi-cell selection is available by mouse dragging over the cells, after a left button mouse clicked continuously.
The selectable property enables you to specify the following options for each IgcColumnComponent. The corresponding column selection will be enabled or disabled if this property is set to true or false, respectively.
This leads to the following three variations:
Single selection - mouse click over the column cell.
Multi column selection - holding ctrl + mouse click over the column cells.
Range column selection - holding shift + mouse click selects everything in between.
Using the ContextMenu event you can add a custom context menu to facilitate your work with IgcGridComponent. With a right click on the grid's body, the event emits the cell on which it is triggered. The context menu will operate with the emitted cell.
If there is a multi-cell selection, we will put logic, which will check whether the selected cell is in the area of the multi-cell selection. If it is, we will also emit the values of the selected cells.
The IgcGridComponent will fetch the copied data and will paste it in a container element.
The template we are going to use to combine the grid with the context menu:
<divclass="container sample"><divclass="wrapper"><igc-gridauto-generate="false"width="50%"height="100%"name="grid"id="grid"><igc-columnfield="ProductID"header="Product ID"></igc-column><igc-columnfield="ProductName"header="Product Name"></igc-column><igc-columnfield="UnitsInStock"header="Units In Stock"data-type="number"></igc-column><igc-columnfield="UnitPrice"header="Units Price"data-type="number"></igc-column><igc-columnfield="Discontinued"data-type="boolean"></igc-column><igc-columnfield="OrderDate"header="Order Date"data-type="date"></igc-column></igc-grid><divid="selectedArea"class="selected-data-area"></div></div></div><divid="menu"style="display: none;"class="contextmenu"><spanid="copySingleCell"class="item"><igc-iconname="content_copy"></igc-icon>Copy Cell Data
</span><spanid="copyRow"class="item"><igc-iconname="content_copy"></igc-icon>Copy Row Data
</span><spanid="copyMultiCells"class="item"><igc-iconname="content_copy"></igc-icon>Copy Cells Data
</span></div></div>html
Select multiple cells and press the right mouse button. The context menu will appear and after selecting Copy cells data the selected data will appear in the right empty box.
<!DOCTYPE html><html><head><title>Sample | Ignite UI | Web Components | infragistics</title><metacharset="UTF-8" /><linkrel="shortcut icon"href="https://static.infragistics.com/xplatform/images/browsers/wc.png"><linkrel="stylesheet"href="https://fonts.googleapis.com/icon?family=Material+Icons" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Kanit&display=swap" /><linkrel="stylesheet"href="https://fonts.googleapis.com/css?family=Titillium Web" /><linkrel="stylesheet"href="https://static.infragistics.com/xplatform/css/samples/shared.v8.css" /><linkrel="stylesheet"href="/src/index.css"type="text/css" /></head><body><divid="root"><divclass="container sample"><divclass="wrapper"><igc-gridauto-generate="false"width="50%"height="100%"name="grid"id="grid"><igc-columnfield="ProductID"header="Product ID"></igc-column><igc-columnfield="ProductName"header="Product Name"></igc-column><igc-columnfield="UnitsInStock"header="Units In Stock"data-type="number"></igc-column><igc-columnfield="UnitPrice"header="Units Price"data-type="number"></igc-column><igc-columnfield="Discontinued"data-type="boolean"></igc-column><igc-columnfield="OrderDate"header="Order Date"data-type="date"></igc-column></igc-grid><divid="selectedArea"class="selected-data-area"></div></div></div><divid="menu"style="display: none;"class="contextmenu"><spanid="copySingleCell"class="item"><igc-iconname="content_copy"></igc-icon>Copy Cell Data
</span><spanid="copyRow"class="item"><igc-iconname="content_copy"></igc-icon>Copy Row Data
</span><spanid="copyMultiCells"class="item"><igc-iconname="content_copy"></igc-icon>Copy Cells Data
</span></div></div><!-- This script is needed only for parcel and it will be excluded for webpack -->
<% if (false) { %>
<scriptsrc="src/index.ts"></script>
<% } %>
</body></html>html
When the grid has no primaryKey set and remote data scenarios are enabled (when paging, sorting, filtering, scrolling trigger requests to a remote server to retrieve the data to be displayed in the grid), a row will lose the following state after a data request completes: