es-grid-template
Version:
es-grid-template
67 lines (58 loc) • 2.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.OperatorFeature = void 0;
var _reactTable = require("@tanstack/react-table");
// TypeScript setup for our new feature with all of the same type-safety as stock TanStack Table features
// define types for our new feature's table options
// Define types for our new feature's table APIs
// export interface OperatorInstance {
// setDensity: (updater: Updater<OpetorState>) => void
// toggleDensity: (value?: OpetorState) => void
// }
// Use declaration merging to add our new feature APIs and state types to TanStack Table's existing types.
const OperatorFeature = exports.OperatorFeature = {
// define the new feature's initial state
getInitialState: state => {
return {
operator: [],
...state
};
},
// define the new feature's default options
getDefaultOptions: table => {
return {
enableOperator: true,
onColumnOperatorChange: (0, _reactTable.makeStateUpdater)('operator', table)
};
},
// if you need to add a default column definition...
// getDefaultColumnDef: <TData extends RowData>(): Partial<ColumnDef<TData>> => {
// return { meta: {} } //use meta instead of directly adding to the columnDef to avoid typescript stuff that's hard to workaround
// },
// define the new feature's table instance methods
// if you need to add row instance APIs...
// createRow: <TData extends RowData>(row, table): void => {},
// if you need to add cell instance APIs...
// createCell: <TData extends RowData>(cell, column, row, table): void => {},
// if you need to add column instance APIs...
// eslint-disable-next-line @typescript-eslint/no-unused-vars
createColumn: (column, table) => {
column.getFilterOperator = () => {
return table.getState().operator?.find(op => op.id === column.id)?.operator ?? undefined;
};
column.setFilterOperator = updater => {
const safeUpdater = old => {
const others = old.filter(op => op.id !== column.id);
return [...others, {
id: column.id,
operator: updater
}];
};
return table.options.onColumnOperatorChange?.(safeUpdater);
};
}
// if you need to add header instance APIs...
// createHeader: <TData extends RowData>(header, table): void => {},
};