Custom Editor

For writing a custom editor, you can use the useInfiniteColumnEditor composable.
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 call the useInfiniteColumnEditor composable in its setup, to have access to cell-related information and to confirm, cancel or reject the edit. The composable returns a plain object, not refs: the editor is created when the edit starts, and initialValue is the value the edit starts with.
CustomEditor.ts
import { defineComponent, h, onMounted, ref } from 'vue';
import { useInfiniteColumnEditor } from '@infinite-table/infinite-vue';

const CustomEditor = defineComponent({
  setup() {
    const { initialValue, confirmEdit, cancelEdit } = useInfiniteColumnEditor();

    const domRef = ref<HTMLInputElement | null>(null);

    onMounted(() => {
      domRef.value?.focus();
    });

    const onKeydown = (event: KeyboardEvent) => {
      const { key } = event;
      if (key === 'Enter' || key === 'Tab') {
        confirmEdit(domRef.value?.value);
      } else if (key === 'Escape') {
        cancelEdit();
      } else {
        event.stopPropagation();
      }
    };

    return () =>
      h('div', [
        h('input', {
          style: { width: '100%' },
          ref: domRef,
          value: initialValue,
          onKeydown,
        }),
      ]);
  },
});
Inside any custom editor component, you can use the useInfiniteColumnCell composable to get access to the cell-related information. It returns a ref.
#
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. The following example uses the MUI X Date Picker, which is a React component, so it's shown in its React version. In Vue, a date editor is written like the editor above: a component that calls the useInfiniteColumnEditor composable and renders the date picker you already use in your project.
#
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.
React only for nowopen
loading demo…