UNPKG

@ackplus/react-tanstack-data-table

Version:

A powerful React data table component built with MUI and TanStack Table

70 lines (69 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getColumnType = getColumnType; exports.getCustomFilterComponent = getCustomFilterComponent; exports.getColumnOptions = getColumnOptions; exports.withIdsDeep = withIdsDeep; exports.isColumnFilterable = isColumnFilterable; /** * Get the type of a column from its metadata */ function getColumnType(column) { var _a; // Check if column has explicit type in columnDef if ((_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.type) { return column.columnDef.type; } return 'text'; // Default to text } function getCustomFilterComponent(column) { var _a, _b; // Check if column has custom filter component in meta return ((_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.filterComponent) || ((_b = column === null || column === void 0 ? void 0 : column.columnDef) === null || _b === void 0 ? void 0 : _b.editComponent); } function getColumnOptions(column) { var _a; // Check if column has explicit options in meta if ((_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.options) { return (column === null || column === void 0 ? void 0 : column.columnDef.options) || []; } // Default options for boolean type const columnType = getColumnType(column); if (columnType === 'boolean') { return [ { value: true, label: 'Yes', }, { value: false, label: 'No', }, ]; } return []; } function withIdsDeep(cols) { return cols.map((c, i) => { var _a, _b; return ({ ...c, id: (_b = (_a = c.id) !== null && _a !== void 0 ? _a : c.accessorKey) !== null && _b !== void 0 ? _b : `col_${i}`, ...(Array.isArray(c.columns) && { columns: withIdsDeep(c.columns) }), }); }); } /** * Determine if a column should be filterable */ function isColumnFilterable(column) { var _a, _b; // Check if column is explicitly marked as filterable if (((_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.filterable) !== undefined) { return (_b = column === null || column === void 0 ? void 0 : column.columnDef) === null || _b === void 0 ? void 0 : _b.filterable; } // Default to filterable for data columns return true; }