Extending existing filters

By default InfiniteTable has the following default filter types:
  • string
  • number
and each of them has a collection of operators that are supported - see filterTypes for the respective list of supported operators.
You may find those operators limiting - but it's easy to extend them and add new operators or even new filter types.

Adding new operators to existing filter types#

You can import defaultFilterTypes from the root of the package.
Adding a new operator to the string filter type
import { defaultFilterTypes } from '@infinite-table/infinite-vue';

// add new operators for the `string` filter type
defaultFilterTypes.string.operators.push({
  name: 'notContains',
  components: { Icon: VueComponentForIcon },
  label: 'Not Contains',
  fn: ({ currentValue, filterValue }) => {
    return (
      typeof currentValue === 'string' &&
      typeof filterValue == 'string' &&
      !currentValue.toLowerCase().includes(filterValue.toLowerCase())
    );
  },
});
When you import the named defaultFilterTypes value and extend it, that will affect all InfiniteTable components in your application.
If you don't want that, you need to use the filterTypes prop of the <DataSource /> component. Either build an entirely new object for filterTypes, or start by cloning defaultFilterTypes and extend it.
#
Enhanced string filter type - new 'Not includes' operator
The string columns have a new Not includes operator.
open
loading demo…

Adding new filter types#

If the existing filter types are not enough, it's easy to add new ones.
As already mentioned, you can either update the value of defaultFilterTypes or use the filterTypes prop of the <DataSource /> component. Updating the value defaultFilterTypes will affect all your InfiniteTable DataGrid components.
Adding a new filter type by updating defaultFilterTypes
import { defaultFilterTypes } from '@infinite-table/infinite-vue';

defaultFilterTypes.bool = {
  defaultOperator: 'eq',
  emptyValues: [null],
  operators: [
    {
      name: 'eq',
      label: 'Equals',
      fn: ({ currentValue, filterValue }) => currentValue === filterValue,
    },
  ],
};
Adding a new filter type by using the filterTypes prop
import {
  DataSource,
  type DataSourcePropFilterTypes,
} from '@infinite-table/infinite-vue';

const filterTypes: DataSourcePropFilterTypes<Developer> = {
  bool: {
    defaultOperator: 'eq',
    emptyValues: [null],
    operators: [
      {
        name: 'eq',
        label: 'Equals',
        fn: ({ currentValue, filterValue }) => currentValue === filterValue,
      },
    ],
  },
};

// <DataSource primaryKey="id" :data="data" :filterTypes="filterTypes" />
When passing filterTypes to the <DataSource /> component, the object will be merged with the defaultFilterTypes. As a result, the existing string and number filterTypes will be preserved, unless explicitly overridden.
#
Writing a bool filter type with a custom filter editor
The canDesign column is using a custom bool filter type with a custom filter editor.
open
loading demo…