@ackplus/react-tanstack-data-table 1.0.25 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/components/rows/empty-data-row.d.ts +2 -1
- package/src/lib/components/table/data-table.js +5 -12
- package/src/lib/components/table/data-table.types.d.ts +1 -1
- package/src/lib/components/toolbar/column-reset-control.js +1 -0
- package/src/lib/utils/column-helpers.d.ts +2 -1
- package/src/lib/utils/column-helpers.js +9 -0
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TableRowProps, TableCellProps, SxProps } from '@mui/material';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
2
3
|
export interface EmptyDataRowProps {
|
|
3
4
|
colSpan: number;
|
|
4
|
-
message: string;
|
|
5
|
+
message: string | ReactNode;
|
|
5
6
|
rowProps?: TableRowProps;
|
|
6
7
|
cellProps?: TableCellProps;
|
|
7
8
|
containerSx?: SxProps;
|
|
@@ -40,7 +40,7 @@ const DEFAULT_INITIAL_STATE = {
|
|
|
40
40
|
pendingLogic: 'AND',
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
|
-
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination =
|
|
43
|
+
exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, columns, data = [], totalRow = 0, idKey = 'id', extraFilter = null, footerFilter = null, dataMode = 'client', initialLoadData = true, onFetchData, onDataStateChange, enableRowSelection = false, enableMultiRowSelection = true, selectMode = 'page', isRowSelectable, onSelectionChange, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, enableExpanding = false, getRowCanExpand, renderSubComponent, enablePagination = false, paginationMode = 'client', enableGlobalFilter = true, enableColumnFilter = false, filterMode = 'client', enableSorting = true, sortingMode = 'client', onSortingChange, exportFilename = 'export', onExportProgress, onExportComplete, onExportError, onServerExport, onExportCancel, enableHover = true, enableStripes = false, tableProps = {}, fitToScreen = true, tableSize: initialTableSize = 'medium', enableStickyHeaderOrFooter = false, maxHeight = '400px', enableVirtualization = false, estimateRowHeight = 52, enableColumnVisibility = true, enableTableSizeControl = true, enableExport = false, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onPaginationChange, onGlobalFilterChange, slots = {}, slotProps = {}, logging, }, ref) {
|
|
44
44
|
var _a;
|
|
45
45
|
const isServerMode = dataMode === 'server';
|
|
46
46
|
const isServerPagination = paginationMode === 'server' || isServerMode;
|
|
@@ -74,7 +74,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
74
74
|
const [selectionState, setSelectionState] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.selectionState) || DEFAULT_INITIAL_STATE.selectionState);
|
|
75
75
|
const [columnFilter, setColumnFilter] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnFilter) || DEFAULT_INITIAL_STATE.columnFilter);
|
|
76
76
|
const [expanded, setExpanded] = (0, react_1.useState)({});
|
|
77
|
-
const [tableSize, setTableSize] = (0, react_1.useState)();
|
|
77
|
+
const [tableSize, setTableSize] = (0, react_1.useState)(initialTableSize || 'medium');
|
|
78
78
|
const [columnOrder, setColumnOrder] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder) || DEFAULT_INITIAL_STATE.columnOrder);
|
|
79
79
|
const [columnPinning, setColumnPinning] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnPinning) || DEFAULT_INITIAL_STATE.columnPinning);
|
|
80
80
|
const [serverData, setServerData] = (0, react_1.useState)(null);
|
|
@@ -96,15 +96,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
96
96
|
const selectionColumnMap = (0, special_columns_utils_1.createSelectionColumn)(Object.assign(Object.assign({}, ((slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn) && typeof slotProps.selectionColumn === 'object' ? slotProps.selectionColumn : {})), { multiSelect: enableMultiRowSelection }));
|
|
97
97
|
columnsMap = [selectionColumnMap, ...columnsMap];
|
|
98
98
|
}
|
|
99
|
-
return columnsMap;
|
|
100
|
-
}, [
|
|
101
|
-
columns,
|
|
102
|
-
slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn,
|
|
103
|
-
slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn,
|
|
104
|
-
enableRowSelection,
|
|
105
|
-
enableExpanding,
|
|
106
|
-
enableMultiRowSelection,
|
|
107
|
-
]);
|
|
99
|
+
return (0, utils_1.withIdsDeep)(columnsMap);
|
|
100
|
+
}, [columns, enableExpanding, enableRowSelection, enableMultiRowSelection, slotProps === null || slotProps === void 0 ? void 0 : slotProps.expandColumn, slotProps === null || slotProps === void 0 ? void 0 : slotProps.selectionColumn]);
|
|
108
101
|
const isExporting = (0, react_1.useMemo)(() => exportController !== null, [exportController]);
|
|
109
102
|
const isSomeRowsSelected = (0, react_1.useMemo)(() => {
|
|
110
103
|
if (!enableBulkActions || !enableRowSelection)
|
|
@@ -561,7 +554,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
|
|
|
561
554
|
table.setColumnPinning(pinning);
|
|
562
555
|
},
|
|
563
556
|
resetColumnPinning: () => {
|
|
564
|
-
table.setColumnPinning(
|
|
557
|
+
table.setColumnPinning(initialStateConfig.columnPinning || { left: [], right: [] });
|
|
565
558
|
},
|
|
566
559
|
},
|
|
567
560
|
columnResizing: {
|
|
@@ -87,7 +87,7 @@ export interface DataTableProps<T> {
|
|
|
87
87
|
enableExport?: boolean;
|
|
88
88
|
enableReset?: boolean;
|
|
89
89
|
loading?: boolean;
|
|
90
|
-
emptyMessage?: string;
|
|
90
|
+
emptyMessage?: string | ReactNode;
|
|
91
91
|
skeletonRows?: number;
|
|
92
92
|
onColumnFiltersChange?: (filterState: ColumnFilterState) => void;
|
|
93
93
|
onPaginationChange?: (pagination: PaginationState) => void;
|
|
@@ -13,6 +13,7 @@ function ColumnResetControl(props = {}) {
|
|
|
13
13
|
const handleResetLayout = () => {
|
|
14
14
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
15
15
|
const actions = props.resetActions || ['columnOrder', 'columnPinning', 'columnSizing'];
|
|
16
|
+
console.log('actions', actions);
|
|
16
17
|
if (!(apiRef === null || apiRef === void 0 ? void 0 : apiRef.current))
|
|
17
18
|
return;
|
|
18
19
|
if (actions.includes('columnOrder')) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Column } from "@tanstack/react-table";
|
|
1
|
+
import { Column, ColumnDef } from "@tanstack/react-table";
|
|
2
2
|
export type ColumnType = 'text' | 'number' | 'date' | 'boolean' | 'select' | 'actions';
|
|
3
3
|
export declare function getColumnType(column: Column<any, unknown>): ColumnType;
|
|
4
4
|
export declare function getCustomFilterComponent(column: Column<any, unknown>): any;
|
|
5
5
|
export declare function getColumnOptions(column: Column<any, unknown>): any[];
|
|
6
|
+
export declare function withIdsDeep<T>(cols: ColumnDef<T, any>[]): ColumnDef<T, any>[];
|
|
6
7
|
export declare function isColumnFilterable(column: Column<any, unknown>): boolean;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getColumnType = getColumnType;
|
|
4
4
|
exports.getCustomFilterComponent = getCustomFilterComponent;
|
|
5
5
|
exports.getColumnOptions = getColumnOptions;
|
|
6
|
+
exports.withIdsDeep = withIdsDeep;
|
|
6
7
|
exports.isColumnFilterable = isColumnFilterable;
|
|
7
8
|
function getColumnType(column) {
|
|
8
9
|
var _a;
|
|
@@ -35,6 +36,14 @@ function getColumnOptions(column) {
|
|
|
35
36
|
}
|
|
36
37
|
return [];
|
|
37
38
|
}
|
|
39
|
+
function withIdsDeep(cols) {
|
|
40
|
+
return cols.map((c, i) => {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
return (Object.assign(Object.assign(Object.assign({}, c), { id: (_b = (_a = c.id) !== null && _a !== void 0 ? _a : c.accessorKey) !== null && _b !== void 0 ? _b : `col_${i}` }), (Array.isArray(c.columns) && {
|
|
43
|
+
columns: withIdsDeep(c.columns)
|
|
44
|
+
})));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
38
47
|
function isColumnFilterable(column) {
|
|
39
48
|
var _a, _b;
|
|
40
49
|
if (((_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.filterable) !== undefined) {
|