[!Note] Please note that this control has been deprecated and replaced with the Grid component, and as such, we recommend migrating to that control. This will not be receiving any new features, bug fixes will be deprioritized. For help or questions on migrating your codebase to the Data Grid, please contact support.

    Web Components Grid Editing

    The Ignite UI for Web Components Data Table / Data Grid supports cell and row editing with batch updating. Note, this is currently limited to non-templated columns.

    Web Components Grid Editing Example

    Overview

    Editing in the Web Components data grid is configured by using the editMode option of the Web Components grid. This property takes three different options, listed below:

    • None: Editing is not enabled.
    • Cell: Allow cells to enter edit mode and commit the value on exiting edit mode.
    • CellBatch: Allows cells to enter edit mode but changes will be cached later until they are committed.
    • Row: Allow rows to enter edit mode and commit the value on exit.

    When set to CellBatch, in order to commit the changes you must perform the commitEdits method from the grid. The grid will italicize the cells until they are committed providing control over when to push changes back to the datasource.

    In addition, error handling can be performed by hooking the onCellValueChanging event and inspecting new values before they are committed. The grid exposes a setEditError method that can output an error message. This keeps the cell in edit mode until a valid value is entered. Otherwise the grid's rejectEdit method can be performed to revert the invalid value. If no invalid value is found, you can also commit your changes by calling the grid's acceptEdit method.

    Commits can be approved or declined at the grid level by hooking onDataCommitting via the acceptCommit or rejectCommit methods passing the commitID event argument as the parameter. This event also exposes a changes collection which stores all the modifications prior to being committed. For example, you can check if a commit was from an add, update, or delete operation via the TransactionType property exposed on the changes collection and perform an acceptCommit or rejectCommit when necessary.

    Excel Style Editing

    editOnKeyPress enables you to instantly begin editing when typing similar to how Excel behaves. In addition you may set the editModeClickAction property to SingleClick to allow users to quickly edit cells while navigating to other cells. By default double-clicking is required to enter edit mode.

    Code Snippet

    The following demonstrates how to configure editing on the data grid and committing the data.

    <button id="clickCommit">Commit</button>
    <igc-data-grid id="grid"
        height="100%"
        width="100%"
        activation-mode="Cell"
        edit-mode="Cell">
    </igc-data-grid>
    
    import { IgcDataGridComponent } from 'igniteui-webcomponents-grids';
    
    this.onCommitClick = this.onCommitClick.bind(this);
    
    public onCommitClick() {
        this.grid.commitEdits();
    }
    

    Undo/Redo batch changes

    The following demonstrates how to revert changes while batch updating is enabled.

    <igc-data-grid id="grid"
          height="100%"
          width="100%"
          activation-mode="Cell"
          edit-mode="Cell">
    </igc-data-grid>
    <button id="undoClick" disabled="true">Undo</button>
    <button id="redoClick" disabled="true">Redo</button>
    
    import { IgcDataGridComponent } from 'igniteui-webcomponents-grids';
    
    public onUndoClick() {
        this.grid.undo();
        if (this.grid.editMode === EditModeType.CellBatch && this.redo !== null)
        {
            this.redo.disabled = false;
        }
    }
    
    public onRedoClick() {
        this.grid.redo();
    }
    

    Error Validation and Commit Integrity

    The following demonstrates how incorporate error by checking if cells are empty when leaving edit mode and accepts commits that are from updated cells only.

    <igc-data-grid
        id="grid"
        height="calc(100% - 50px)"
        width="100%"
        activation-mode="Cell"
        selection-mode="SingleRow"
        default-column-min-width="125"
        is-column-options-enabled="true"
        auto-generate-columns="false"
        edit-mode="Cell">
    
    import { IgcGridDataCommittingEventArgs } from 'igniteui-webcomponents-grids';
    import { TransactionType } from 'igniteui-webcomponents-core'
    
    this.onCellValueChanging = this.onCellValueChanging.bind(this);
    this.grid.cellValueChanging = this.onCellValueChanging;
    
    this.onDataCommitting = this.onDataCommitting.bind(this);
    this.grid.dataCommitting = this.onDataCommitting;
    
    
    public onCellValueChanging (s: IgcDataGridComponent, e: IgcGridCellValueChangingEventArgs) {
        if (s.editMode === EditModeType.CellBatch && this.undo !== null)
        {
            this.undo.disabled = false;
        }
    
        //check if value is empty upon exiting edit mode.
        if (e.newValue === "") {
            s.setEditError(e.editID, "Error, cell is empty");
            //or revert changes
            s.rejectEdit(e.editID);
        }
        else {
            s.acceptEdit(e.editID);
        }
    }
    
    public onDataCommitting (s: IgcDataGridComponent, e: IgcGridDataCommittingEventArgs) {
        if (e.changes[0].transactionType === TransactionType.Update) {
            //commit was passed
            s.acceptCommit(e.commitID);
        }
        else{
            //commit was prevented
            s.rejectCommit(e.commitID);
        }
    }
    

    API References