Blazor Hierarchical Grid Row Adding

    The Ignite UI for Blazor Row Adding feature in Blazor Hierarchical Grid enables users to input and submit new data records without navigating to a separate form or page. With the IgbHierarchicalGrid, users can manipulate data through inline row adding and a powerful API for CRUD operations. Add an IgbActionStrip component with editing actions enabled in the grid's template. After that hover a row and use the provided button. Finally press ALT + + to spawn the row adding UI.

    Blazor Hierarchical Grid Row Adding Example

    EXAMPLE
    MODULES
    DATA
    RAZOR
    CSS

    Like this sample? Get access to our complete Ignite UI for Blazor toolkit and start building your own apps in minutes. Download it for free.

    Row Adding Usage

    Then define a IgbHierarchicalGrid with bound data source, RowEditable set to true and an IgbActionStrip component with editing actions enabled. The AddRow input controls the visibility of the button that spawns the row adding UI.

    <IgbHierarchicalGrid AutoGenerate="false" Id="hGrid" PrimaryKey="Debut" RowEditable="true">
        <IgbColumn Field="Artist" Header="Artist" DataType="GridColumnDataType.String"></IgbColumn>
        <IgbColumn Field="HasGrammyAward" Header="Has Grammy Award" DataType="GridColumnDataType.Boolean"></IgbColumn>
        <IgbColumn Field="Debut" Header="Debut" DataType="GridColumnDataType.Number"></IgbColumn>
        <IgbColumn Field="GrammyNominations" Header="Grammy Nominations" DataType="GridColumnDataType.Number"></IgbColumn>
        <IgbColumn Field="GrammyAwards" Header="Grammy Awards" DataType="GridColumnDataType.Number"></IgbColumn>
    
        <IgbActionStrip>
            <IgbGridEditingActions AddRow="true"></IgbGridEditingActions>
        </IgbActionStrip>
        
        <IgbRowIsland AutoGenerate="false" Key="Albums" PrimaryKey="USBillboard200" RowEditable="true">
            <IgbColumn Field="Album" Header="Album" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="LaunchDate" Header="Launch Date" DataType="GridColumnDataType.Date"></IgbColumn>
            <IgbColumn Field="BillboardReview" Header="Billboard Review" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="USBillboard200" Header="US Billboard 200" DataType="GridColumnDataType.Number"></IgbColumn>
            <IgbColumn Field="GrammyAwards" Header="Grammy Awards" DataType="GridColumnDataType.Number"></IgbColumn>
    
            <IgbRowIsland AutoGenerate="false" Key="Songs" PrimaryKey="Number" RowEditable="true">
                <IgbColumn Field="Number" Header="Number" DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="Title" DataType="GridColumnDataType.String"></IgbColumn>
                <IgbColumn Field="Released" DataType="GridColumnDataType.Date"></IgbColumn>
                <IgbColumn Field="Genre" DataType="GridColumnDataType.String"></IgbColumn>
    
                <IgbActionStrip>
                    <IgbGridEditingActions AddRow="true"></IgbGridEditingActions>
                </IgbActionStrip>
            </IgbRowIsland>
    
            <IgbActionStrip>
                <IgbGridEditingActions AddRow="true"></IgbGridEditingActions>
            </IgbActionStrip>
        </IgbRowIsland>
    </IgbHierarchicalGrid>
    razor

    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 IgbGridEditingActions input controlling the visibility of the add row button may use the action strip context (which is of type IgbRowType to fine tune which records the button shows for.

    The internal BaseTransactionService is automatically provided for IgbHierarchicalGrid. It holds pending cell changes until the row state is submitted or cancelled.

    Start Row Adding Programmatically

    IgbHierarchicalGrid 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. You can also make the UI spawn as the very first row in the grid by passing null for the first parameter.

    @code {
        await this.grid.BeginAddRowByIdAsync('ALFKI', false);  // Spawns the add row UI under the row with PK 'ALFKI'
        await this.grid.BeginAddRowByIdAsync(null, false);     // Spawns the add row UI as the first record
    }
    razor

    The beginAddRowByIndex method works similarly but requires you to specify the index at which the UI should spawn. Allowed values range between 0 and the size of the data view - 1.

    @code {
        await this.grid.BeginAddRowByIndexAsync(10);   // Spawns the add row UI at index 10
        await this.grid.BeginAddRowByIndexAsync(0);    // Spawns the add row UI as the first record
    }
    razor

    Positioning

    • The default position of row add UI is below the row that the end user clicked the add row button for.

    • The IgbHierarchicalGrid scrolls to fully display the add row UI automatically.

    • 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 Hierarchical 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 IgbHierarchicalGrid. In a IgbHierarchicalGrid 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 IgbHierarchicalGrid to its position if it is not in view.

    Keyboard Navigation

    • ALT + + - Enters edit mode for adding a row
    • 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 IgbHierarchicalGrid 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.

    • When spawning the UI for the IgbHierarchicalGrid, any child layout currently expanded for a row that the end user clicks the add row button for is collapsed.

    Customizing Row Adding Overlay

    Customizing Text

    Customizing the text of the row adding overlay is possible using the RowAddTextDirective.

    <IgbHierarchicalGrid Data="data" PrimaryKey="ProductID" AutoGenerate="false" RowEditable="true" RowAddTextTemplate="addTextTemplate">
    </IgbHierarchicalGrid>
    
    @code {
        private RenderFragment<IgbGridEmptyTemplateContext> addTextTemplate = (context) =>
        {
            return @<span>Adding Row</span>;
        };
    }
    razor

    Customizing Buttons

    Customizing the buttons of the row editing overlay is possible by using the RowEditActions template.

    <IgbHierarchicalGrid Data="data" PrimaryKey="ProductID" AutoGenerate="false" RowEditable="true" RowEditActionsTemplateScript="rowEditActionsTemplate">
    </IgbHierarchicalGrid>
    
    //In JavaScript:
    igRegisterScript("rowEditActionsTemplate", (endRowEdit) => {
        var html = window.igTemplating.html;
        return html`<div class="row-actions">
            <button @click="${evt => endRowEdit.implicit(false, evt)}">Cancel</button>
            <button @click="${evt => endRowEdit.implicit(true, evt)}">Apply</button>
        </div>`
    }, false);
    razor

    Note: Using RowEditActions template will change edit actions for both editing and adding overlay buttons.

    Styling

    The row adding UI comprises the buttons in the IgbActionStrip 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:

    API References

    Additional Resources

    Our community is active and always welcoming to new ideas.