v7.3.0
SupportExamplesFree Trial

CellEdit
Feature

Adding this feature to the grid and other Bryntum products which are based on the Grid (i.e. Scheduler, SchedulerPro, and Gantt) enables cell editing. Any subclass of Field can be used as editor for the Column. The most popular are:

Usage instructions:

Start editing

  • Double click on a cell
  • Press Enter or F2 with a cell selected (see Keyboard shortcuts below)
  • It is also possible to change double click to single click to start editing, using the triggerEvent config
new Grid({
   features : {
       cellEdit : {
           triggerEvent : 'cellclick'
       }
   }
});

Instant update

If instantUpdate on the column is set to true, record will be updated instantly as value in the editor is changed. In combination with autoCommit it could result in excessive requests to the backend. By default instantUpdate is false, but it is enabled for some special columns, such as Duration column in Scheduler Pro and all date columns in Gantt.

Keyboard shortcuts

While not editing

Keys Action Action description
Enter startEditing Starts editing currently focused cell
F2 startEditing Starts editing currently focused cell

While editing

Keys Action Weight Action description
Enter finishAndEditNextRow Finish editing and start editing the same cell in next row
Shift+Enter finishAndEditPrevRow Finish editing and start editing the same cell in previous row
F2 finishEditing Finish editing
Ctrl+Enter finishAllSelected If multiEdit is active, this applies new value on all selected rows/cells
Ctrl+Enter finishEditing Finish editing
Escape cancelEditing By default, first reverts the value back to its original value, next press cancels editing
Tab finishAndEditNextCell 100 Finish editing and start editing the next cell with a configured editor
Shift+Tab finishAndEditPrevCell 100 Finish editing and start editing the previous cell with a configured editor
Please note that Ctrl is the equivalent to Command and Alt is the equivalent to Option for Mac users

When using the Tab key to navigate between cells, the editor will skip over cells which contain naturally focusable elements, such as buttons or input fields. To have these included in the tabbing, configure the tabToFocusables setting as true.

For more information on how to customize keyboard shortcuts, please see our guide.

Editor configuration

Columns specify editor in their configuration. Editor can also by set by using a column type. Columns may also contain these three configurations which affect how their cells are edited:

Preventing editing of certain cells

You can prevent editing on a column by setting editor to false:

new Grid({
   columns : [
      {
         type   : 'number',
         text   : 'Age',
         field  : 'age',
         editor : false
      }
   ]
});

To prevent editing in a specific cell, listen to the beforeCellEditStart and return false:

grid.on('beforeCellEditStart', ({ editorContext }) => {
    return editorContext.column.field !== 'id';
});

Choosing field on the fly

To use an alternative input field to edit a cell, listen to the beforeCellEditStart and set the editor property of the context to the input field you want to use:

grid.on('beforeCellEditStart', ({ editorContext }) => {
    return editorContext.editor = myDateField;
});

Loading remote data into a combo box cell editor

If you need to prepare or modify the data shown by the cell editor, e.g. load remote data into the store used by a combo, listen to the startCellEdit event:

// A server endpoint returning data like:
// [{ id : 123, name : 'Bob Mc Bob' }, { id : 345, name : 'Lind Mc Foo' }]
const employeeStore = new AjaxStore({ readUrl : '/cities' });

new Grid({ // Example data including a city field which is an id used to look up entries in the cityStore above data : [ { id : 1, name : 'Task 1', employeeId : 123 }, { id : 2, name : 'Task 2', employeeId : 345 } ], columns : [ { text : 'Task', field : 'name' }, { text : 'Assigned to', field : 'employeeId', editor : { type : 'combo', store : employeeStore, // specify valueField'/'displayField' to match the data format in the employeeStore store valueField : 'id', displayField : 'name' }, renderer : ({ value }) { // Use a renderer to show the employee name, which we find by querying employeeStore by the id of the grid record return employeeStore.getById(value)?.name; } } ], listeners : { // When editing, you might want to fetch data for the combo store from a remote resource startCellEdit({ editorContext }) { const { record, editor, column } = editorContext; if (column.field === 'employeeId') { // Load possible employees to assign to this particular task editor.inputField.store.load({ task : record.id }); } } } });

Editing on touch devices

On touch devices, a single tap navigates and tapping an already selected cell after a short delay starts the editing.

This feature is enabled by default.

Validation

To validate the cell editing process you can use the finalizeCellEdit config. Please refer to its documentation for details.

The following example requires a name of a minimum of 5 characters and a score of less than 1,000 for Paris city.

// grid with cell editing const grid = new Grid({ appendTo : targetElement, // makes grid as high as it needs to be to fit rows autoHeight : true, features : { // cellEditing is enabled by default, so this is not necessary cellEdit : true }, data : DataGenerator.generateData(5), columns : [ // basic columns has a TextField as editor by default { field : 'name', text : 'Name', flex : 1, // Invoked on final edit of input field, typically after pressing enter or blurring the field. finalizeCellEdit : ({ value }) => { // returning true will accept the new value otherwise it shows the return statement as error message return value.trim().length < 5 ? 'Name should be at least 5 characters' : true; } }, // a custom editor can be specified { field : 'city', text : 'City', flex : 1, editor : { type : 'combo', items : ['Stockholm', 'New York', 'Montreal'] } }, // column types may specify an editor // NumberColumn for example uses a NumberField { type : 'number', field : 'score', text : 'Score', flex : 1, finalizeCellEdit : ({ value, record }) => { // record contains sibling column's data const { city } = record; // Perform validation based on a sibling column if (city == 'Paris' && value > 999) { return "Score can't be higher than 999 for Paris"; } return true; } }, // specify editor: false to make a column "readonly" { type : 'number', field : 'age', text : 'Age (readonly)', flex : 1, editor : false } ] });

You can use the value parameter to add validation to accept a value of minimum 5 characters:

// Column
{
 field: 'name',
 text: 'Name',
 flex: 1,
 finalizeCellEdit: ({ value }) => {
     // Implement your validation logic here
     if (value.trim().length < 5) {
         return "Name should be at least 5 characters";
     }

// Return true to allow the edit to be finalized return true; } }

Along with the value, it also contains other parameters, such as data.record property, which provides a way to access and validate other columns based on their values.

In the following example, validation is performed based on the 'Score' column's value and the value of its sibling column ('City'):

      {
          type             : 'number',
          field            : 'score',
          text             : 'Score',
          flex             : 1,
          finalizeCellEdit : ({ value, record }) => {

// record contains sibling column's data e.g. city const { city } = record;

// Perform validation based on a sibling column if (city == 'Paris' && value > 999) { return "Score can't be higher than 999 for Paris"; } return true; } },

See also

  • RowEdit - Edit an entire row in a popup form
  • editor - Per-column editor config
No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • Set to true to select the field text when editing starts

  • blurAction : 'complete'/'cancel'complete

    What action should be taken when focus moves leaves the cell editor, for example when clicking outside. May be 'complete' or 'cancel'.

  • Set to false to not start editing next record when user presses enter inside a cell editor (or previous record if SHIFT key is pressed). This is set to false when autoEdit is true. Please note that these key combinations could be different if a customized keyMap is used.

  • editorClass : Widget
    internal

    Class to use as an editor. Default value: Editor

  • See Keyboard shortcuts for details

  • scrollAction : 'complete'/'cancel'/null

    What action should be taken when the editor is scrolled out of view, for example when using a mousewheel to scroll the grid. May be 'complete' or 'cancel' or null.

    Has a corresponding runtime scrollAction property.

  • Internal listeners, that cannot be removed by the user.

  • Set to true to start editing when user starts typing text on a focused cell (as in Excel)

    Has a corresponding runtime autoEdit property.

  • ignoreCSSSelector : Stringbutton,.b-icon,.fa,svg,input,.b-widget
    GridEditBase

    A CSS selector for elements that when clicked, should not trigger editing. Useful if you render actionable icons or buttons into a grid cell.

  • The widget which this plugin is to attach to.

    Has a corresponding runtime client property.

  • Set to false to disable localization of this object.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isCellEdit : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of CellEdit class, or subclass thereof.
  • isDelayable : Booleantrue
    READONLY
    static
    ADVANCED
    Delayable
    Identifies an object as an instance of Delayable class, or subclass thereof.
  • isEvents : Booleantrue
    READONLY
    static
    ADVANCED
    Events
    Identifies an object as an instance of Events class, or subclass thereof.
  • isLocalizable : Booleantrue
    READONLY
    static
    ADVANCED
    Localizable
    Identifies an object as an instance of Localizable class, or subclass thereof.
  • properties : Object
    internal
    static
    GridEditBase

    A class property getter for the default values of internal properties for this class.

  • scrollAction : 'complete'/'cancel'/null

    What action should be taken when the editor is scrolled out of view, for example when using a mousewheel to scroll the grid. May be 'complete' or 'cancel' or null.

    Has a corresponding scrollAction config.

  • emptyArray : Array
    internal
    READONLY
    GridEditBase

    An empty array that can be used as a default value.

  • emptyObject : Object
    internal
    READONLY
    GridEditBase

    An empty object that can be used as a default value.

  • isCellEdit : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of CellEdit class, or subclass thereof.
  • isGridEditBase : Booleantrue
    READONLY
    ADVANCED
    GridEditBase
    Identifies an object as an instance of GridEditBase class, or subclass thereof.
  • isInstancePlugin : Booleantrue
    READONLY
    ADVANCED
    GridEditBase
    Identifies an object as an instance of InstancePlugin class, or subclass thereof.
  • Returns the record currently being edited, or null

  • Set to true to start editing when user starts typing text on a focused cell (as in Excel)

    Has a corresponding autoEdit config.

  • Is editing currently active?

  • config : Object
    READONLY
    ADVANCED
    GridEditBase

    Returns a copy of the full configuration which was used to configure this object.

  • isConstructing : Boolean
    READONLY
    ADVANCED
    GridEditBase

    This property is set to true before the constructor returns.

  • isDestroying : Boolean
    READONLY
    ADVANCED
    GridEditBase

    This property is set to true on entry to the destroy method. It remains on the objects after returning from destroy(). If isDestroyed is true, this property will also be true, so there is no need to test for both (for example, comp.isDestroying || comp.isDestroyed).

  • client : Widget
    READONLY
    ADVANCED
    GridEditBase

    The Widget which was passed into the constructor, which is the Widget we are providing extra services for.

    Has a corresponding client config.

  • Get the global LocaleHelper

  • Get the global LocaleManager

Functions

Functions are methods available for calling on the class
  • onClassMixedIn( )
    internal
    static
    GridEditBase

    This optional class method is called when a class is mixed in using the mixin() method.

  • initClass( )
    static
    ADVANCED
    GridEditBase

    Registers this class type with its Factory

  • onEditorFocusOut( )
    private
    ASYNC

    Cancel editing on widget focusout

  • onTapOut( )
    private
    ASYNC

    Cancel edit on touch outside of grid for mobile Safari (focusout not triggering unless you touch something focusable)

  • Internal function used to hook destroy() calls when using thisObj

  • Internal function used restore hooked destroy() calls when using thisObj

  • doDestroy( )
    internal
    Events

    Auto detaches listeners registered from start, if set as detachable

  • once( )
    private
    Events

    Internal function used to run a callback function after an event is triggered

  • Removes all listeners registered to this object by the application.

  • This will merge a feature's (subclass of InstancePlugin) keyMap with it's client's keyMap.

  • onCellClick( )
    private
    ASYNC
    GridEditBase

    Starts editing if user taps selected cell again on touch device. Chained function called when user clicks a cell.

  • Event handler added when editing is active called when user clicks a cell in the grid during editing. It finishes editing and moves editor to the selected cell instead.

  • onElementClick( )
    private
    ASYNC

    Finish editing if clicking below rows (only applies when grid is higher than rows). Also finish if event target is the subgrid which can happen if the pointer is moved during mouse down.

  • onGridRefreshed( )
    private

    Realign editor if grid renders rows while editing is ongoing (as a result to autoCommit or WebSocket data received).

  • Update the input field if underlying data changes during edit.

  • Called when the user triggers the edit action in triggerEvent config. Starts editing.

Events

Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

Event handlers

Event handlers are callbacks called as a result of certain actions in this class

Type definitions

id: cellEdit

Source path

Grid/feature/CellEdit.js

Demo

examples/celledit

Contents