Custom Editor

View as Markdown
For writing a custom editor, you can use the useInfiniteColumnEditor hook.
For any column (or column type - which can then get applied to multiple columns), you can specify a custom editor component to be used for editing the column's value, via the column.components.Editor property.
const columns: InfiniteTablePropColumns<Developer> = {
  id: {
    field: 'id',
    defaultEditable: false,
  },
  firstName: {
    field: 'firstName',
    components: {
      // this is using a custom editor component
      Editor: CustomEditor,
    },
  },
  age: {
    field: 'age',
    type: 'number',
    defaultEditable: false,
  },
  stack: { field: 'stack' },
  currency: { field: 'currency' },
};
The editor component should use the useInfiniteColumnEditor hook to have access to cell-related information and to confirm, cancel or reject the edit.
CustomEditor.tsx
import { useInfiniteColumnEditor } from '@infinite-table/infinite-react';
const CustomEditor = () => {
  const { initialValue, confirmEdit, cancelEdit } = useInfiniteColumnEditor();

  const domRef = React.useRef<HTMLInputElement>(null);

  const onKeyDown = useCallback((event: React.KeyboardEvent) => {
    const { key } = event;
    if (key === 'Enter' || key === 'Tab') {
      confirmEdit(domRef.current?.value);
    } else if (key === 'Escape') {
      cancelEdit();
    } else {
      event.stopPropagation();
    }
  }, []);

  return (
    <div>
      <input
        style={{ width: '100%' }}
        autoFocus
        ref={domRef}
        defaultValue={initialValue}
        onKeyDown={onKeyDown}
      />
    </div>
  );
};
Inside any custom editor component, you can use the useInfiniteColumnCell hook to get access to the cell-related information.
#
Using a custom editor
In this example, the salary column is configured with a custom editor component.
open
loading demo…

Using Custom Date Editors#

A common use-case is integrating date editors, so in the following example we'll use the MUI X Date Picker component.
#
Using MUI X Date Picker for editing dates in the DataGrid
This is a basic example integrating with the MUI X Date Picker - click any cell in the Birth Date column to show the date picker.
open
loading demo…