React Grid Row Editing

    The Ignite UI for React Row Editing feature in React Grid allows editing data directly within the IgrGrid. On top of this convenient way to manipulate data, there’s a powerful API for full CRUD operations. You can perform grid row editing by clicking on a row and pressing Enter key. Another quick way is to double click with the mouse on the row that needs to be modified.

    React Grid Row Editing Example

    The following sample demonstrates how to enable row editing in the IgrGrid. Changing a cell value and then clicking or navigating to another cell on the same row won't update the row value until confirmed by using the Done button, or discarded by using Cancel button.

    [!Note] When a row is in edit mode, clicking on a cell in another row will act like the "Done" button is pressed, submitting all changes made in the previous row. If the newly focused cell is editable, the new row enters edit mode as well. However, if the cell is not editable, only the previous row exits edit mode.

    Row Editing Usage

    Define a IgrGrid with bound data source and rowEditable set to true:

    const unitsInStockCellTemplate = (ctx: IgrCellTemplateContext) => {
        return (
            <>
                <input name="units" value={ctx.cell.value} style={{color: "black"}} />;
            </>
        );
    }
    
    <IgrGrid primaryKey="ProductID" width="100%" height="500px" rowEditable={true}>
        <IgrColumn field="ProductID" header="Product ID" editable={false}></IgrColumn>
        <IgrColumn field="ReorderLevel" header="ReorderLever" dataType="number"></IgrColumn>
        <IgrColumn field="ProductName" header="ProductName" dataType="string"></IgrColumn>
        <IgrColumn field="UnitsInStock" header="UnitsInStock" dataType="number" bodyTemplate={unitsInStockCellTemplate}></IgrColumn>
        <IgrColumn field="OrderDate" dataType="date"></IgrColumn>
        <IgrColumn field="Discontinued" header="Discontinued" dataType="boolean"></IgrColumn>
    </IgrGrid>
    

    [!Note] Setting primary key is mandatory for row editing operations.

    [!Note] Enabling editing for individual columns is not necessary. Using the rowEditable property in the IgrGrid, all rows, with defined field property (excluding the primary row) will be editable. If you want to disable editing for a specific column, simply set the editable input of that column to false.

    [!Note] The IgrGrid utilizes BaseTransactionService - an internal provider that holds pending cell changes until the row state is either submitted or cancelled.

    Positioning

    • La posición predeterminada de la superposición estará debajo de la fila que está en modo de edición.

    • Si no hay espacio debajo de la fila, aparecerá una superposición encima de la fila.

    • Una vez que se muestra, arriba o abajo, la superposición mantendrá esta posición durante el desplazamiento, hasta que se cierre la superposición.

    Behavior

    • Si la fila está en modo de edición, la edición continuará si se hace clic en una celda de la misma fila.

    • Al hacer clic en el botón "Listo", finalizará la edición de la fila y enviará los cambios a la fuente de datos o a una transacción, si está disponible. Además, la fila saldrá del modo de edición.

    • Al hacer clic en el botón "Cancelar", se revertirán todos los cambios actuales en la fila y la fila saldrá del modo de edición.

    • Si la fila está en modo de edición, al hacer clic en una celda de otra fila finalizará la edición de la fila actual y se enviarán nuevos cambios en la fila (el mismo comportamiento al hacer clic en el botón "Listo"). Si la nueva celda que recibe el foco es editable, entonces la nueva fila también ingresa al modo de edición, mientras que si la celda no es editable, solo la fila anterior sale del modo de edición.

    • If row is in edit mode and IgrGrid is scrolled so that row goes outside the visible area, the latter will be still in edit mode. When IgrGrid is scrolled, so that the row is visible again, the row will be still in edit mode. When clicked outside the IgrGrid, the cell will also stay in edit mode.

    • Al realizar operaciones de clasificación, filtrado, búsqueda y ocultación, se revertirán todos los cambios actuales en la fila y la fila saldrá del modo de edición.

    • Al realizar operaciones de paginación, cambio de tamaño, fijación y movimiento, saldrá del modo de edición y enviará el último valor.

    • Each modified cell gets edited style until row edit is finished. This is the behavior, when IgrGrid is not provided with transactions. When transactions are available - then cell edit style is applied until all the changes are committed.

    Keyboard Navigation

    • ENTER y F2 entra en modo de edición de filas

    • ESC Sale del modo de edición de fila y no envía ninguno de los cambios de celda realizados mientras la fila estaba en modo de edición.

    • TAB mueve el foco de una celda editable en la fila a la siguiente y de la celda editable más a la derecha a los botones CANCELAR y LISTO. La navegación desde el botón LISTO va a la celda editable más a la izquierda dentro de la fila actualmente editada.

    Feature Integration

    • Cualquier operación de cambio de datos finalizará las operaciones de edición de filas y enviará los cambios de filas actuales. Esto incluirá operaciones como ordenar, cambiar criterios de agrupación y filtrado, paginación, etc.

    • Los resúmenes se actualizarán una vez finalizada la edición de la fila. Lo mismo es válido para otras funciones como ordenar, filtrar, etc.

    • Expandir y contraer filas agrupadas no finalizará la edición de la fila actual.

    Customizing Row Editing Overlay

    Customizing Text

    Es posible personalizar el texto de la superposición de edición de filas mediante plantillas.

    The RowChangesCount property is exposed and it holds the count of the changed cells.

    const rowEditTextTemplate = (ctx: IgrGridRowEditTextTemplateContext) =>{
        return (
            <>
                Changes: {ctx.implicit}
            </>
        );
    }
    

    Customizing Buttons

    También es posible personalizar los botones de la superposición de edición de filas mediante plantillas.

    const rowEditActionsTemplate =(ctx: IgrGridRowEditActionsTemplateContext) => {
        const endRowEdit = ctx.implicit;
        return (
            <>
                <button onClick={(event) => endRowEdit(false, event)}>Cancel</button>
                <button onClick={(event) => endRowEdit(true, event)}>Apply</button>
            </>
        );
    }
    

    Styling

    Además de los temas predefinidos, la cuadrícula se puede personalizar aún más configurando algunas de las propiedades CSS disponibles. En caso de que desee cambiar algunos de los colores, primero debe establecer una clase para la cuadrícula:

    <IgrGrid className="grid"></IgrGrid>
    

    Luego configure las propiedades CSS relacionadas para esa clase:

    .grid {
        --ig-banner-banner-background: #e3e3e3;
        --ig-banner-banner-message-color: #423589;
    }
    

    Demo

    Known Issues and Limitations

    • 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:
    • Selección de fila
    • Fila Expandir/contraer
    • Edición de filas
    • Fijación de filas

    API References

    Additional Resources

    Nuestra comunidad es activa y siempre da la bienvenida a nuevas ideas.