The IgcTreeGridComponent provides a convenient way to perform data manipulations through inline row adding and a powerful API for Web Components CRUD operations. Add an IgcActionStrip component with editing actions enabled in the grid's template, hover a row and use the provided button, press ALT + + to spawn the row adding UI or ALT + SHIFT + + to spawn the UI for adding a child for the selected row.
<!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="container fill"><igc-tree-gridauto-generate="false"name="treeGrid"id="treeGrid"id="treeGrid"primary-key="ID"foreign-key="ParentID"row-editable="true"><igc-action-strip
><igc-grid-editing-actionsadd-row="true"add-child="true"></igc-grid-editing-actions></igc-action-strip><igc-columnfield="Name"header="Full Name"data-type="string"resizable="true"sortable="true"filterable="true"editable="true"></igc-column><igc-columnfield="Age"data-type="number"resizable="false"sortable="false"filterable="false"editable="true"></igc-column><igc-columnfield="Title"data-type="string"resizable="true"sortable="true"filterable="true"editable="true"></igc-column><igc-columnfield="HireDate"header="Hire Date"data-type="date"resizable="true"sortable="true"filterable="true"editable="true"></igc-column></igc-tree-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.
Row Adding Usage
Then define a IgcTreeGridComponent with bound data source, rowEditable set to true and an IgcActionStrip component with editing actions enabled. The addRow input controls the visibility of the button that spawns the row adding UI.
Note:
Setting primary key is mandatory for row adding operations.
Note:
Every column excluding the primary key one is editable in the row adding UI by default. If you want to disable editing for a specific column, then you have to set the editable column's input to false.
Note:
The IgcGridEditingActions inputs controlling the visibility of the add row and add child buttons may use the action strip context (which is of type IgcRowType to fine tune which records the buttons show for.
The internal BaseTransactionService is automatically provided for IgcTreeGridComponent. It holds pending cell changes until the row state is submitted or cancelled.
Start Row Adding Programmatically
IgcTreeGridComponent allows to programmatically spawn the add row UI by using two different public methods. One that accepts a row ID for specifying the row under which the UI should spawn and another that works by index. You can use these methods to spawn the UI anywhere within the current data view. Changing the page or specifying a row that is e.g. filtered out is not supported.
Using beginAddRowById requires you to specify the row to use as context for the operation by its RowID (PK). The method then functions as though the end-user clicked on the add row action strip button for the specified row, spawning the UI under it. The second parameter controls if the row is added as a child to the context row or as a sibling. You can also make the UI spawn as the very first row in the grid by passing null for the first parameter.
this.treeGrid.beginAddRowById('ALFKI', true); // Spawns the add row UI to add a child for the row with PK 'ALFKI'this.treeGrid.beginAddRowById(null); // Spawns the add row UI as the first recordtypescript
The beginAddRowByIndex method works similarly but the row to use as context is specified by index.
this.treeGrid.beginAddRowByIndex(10, true); // Spawns the add row UI to add a child for the row at index 10this.treeGrid.beginAddRowByIndex(null); // Spawns the add row UI as the first recordtypescript
Positioning
The default position of row add UI is below the row that the end user clicked the add row button for.
The overlay for the add row UI maintains its position during scrolling.
Behavior
The add row UI has the same behavior as the row editing one as they are designed to provide a consistent editing experience to end users. Please, refer to the Tree Grid Row Editing topic for more information.
After a new row is added through the row adding UI, its position and/or visibility is determined by the sorting, filtering and grouping state of the IgcTreeGridComponent. In a IgcTreeGridComponent that does not have any of these states applied, it appears as the last record. A snackbar is briefly displayed containing a button the end user may use to scroll the IgcTreeGridComponent to its position if it is not in view.
Keyboard Navigation
ALT + + - Enters edit mode for adding a row
ALT + SHIFT + + - Enters edit mode for adding a child
ESC exits row adding mode without submitting any changes
TAB move focus from one editable cell in the row to the next and from the right-most editable cell to the CANCEL and DONE buttons. Navigation from DONE button goes to the left-most editable cell within the currently edited row.
Feature Integration
Any row adding operation will stop if the data view of the IgcTreeGridComponent gets modified. Any changes made by the end user are submitted. Operations that change the data view include but are not limited to sorting, grouping, filtering, paging, etc.
Summaries are updated after the row add operation finishes. The same is valid for the other data view dependant features such as sorting, filtering, etc.
Customizing Row Adding Overlay
Customizing Text
Customizing the text of the row adding overlay is possible using the RowAddTextDirective.
The row adding UI comprises the buttons in the IgcActionStrip editing actions, the editing editors and overlay, as well as the snackbar which allows end users to scroll to the newly added row. To style these components you may refer to these comprehensive guides in their respective topics: