@ackplus/react-tanstack-data-table 1.0.32 → 1.0.34

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ackplus/react-tanstack-data-table",
3
3
  "type": "commonjs",
4
- "version": "1.0.32",
4
+ "version": "1.0.34",
5
5
  "description": "A powerful React data table component built with MUI and TanStack Table",
6
6
  "keywords": [
7
7
  "react",
@@ -14,4 +14,5 @@ interface DraggableHeaderProps<T> {
14
14
  [key: string]: any;
15
15
  }
16
16
  export declare function DraggableHeader<T>(props: DraggableHeaderProps<T>): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<string | number | bigint | boolean | React.ReactPortal | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | Iterable<React.ReactNode>> | import("react/jsx-runtime").JSX.Element;
17
+ export declare const DraggableHeaderMemo: typeof DraggableHeader;
17
18
  export {};
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DraggableHeaderMemo = void 0;
3
4
  exports.DraggableHeader = DraggableHeader;
4
5
  const tslib_1 = require("tslib");
5
6
  const jsx_runtime_1 = require("react/jsx-runtime");
6
7
  const icons_material_1 = require("@mui/icons-material");
7
8
  const material_1 = require("@mui/material");
8
9
  const react_table_1 = require("@tanstack/react-table");
9
- const react_1 = require("react");
10
+ const react_1 = tslib_1.__importStar(require("react"));
10
11
  const slot_helpers_1 = require("../../utils/slot-helpers");
11
12
  function DraggableHeader(props) {
12
13
  const { header, enableSorting = true, draggable = false, onColumnReorder, containerSx, sortIconProps, alignment, slots, slotProps } = props, otherProps = tslib_1.__rest(props, ["header", "enableSorting", "draggable", "onColumnReorder", "containerSx", "sortIconProps", "alignment", "slots", "slotProps"]);
@@ -184,8 +185,15 @@ function DraggableHeader(props) {
184
185
  };
185
186
  const mergedContainerProps = (0, slot_helpers_1.mergeSlotProps)({
186
187
  ref: headerElementRef,
187
- sx: Object.assign({ display: 'flex', alignItems: 'center', justifyContent: justifyContent, gap: 1, cursor: getCursor(), userSelect: 'none', opacity: isDragging ? 0.5 : 1, backgroundColor: dragOver ? 'rgba(25, 118, 210, 0.08)' : 'transparent', borderLeft: dragOver ? '2px solid #1976d2' : 'none', padding: dragOver ? '0 0 0 -2px' : '0', width: '100%', height: '100%', '&:active': {
188
+ sx: Object.assign({ display: 'flex', alignItems: 'center', justifyContent: justifyContent, gap: 1, cursor: getCursor(), userSelect: 'none', opacity: isDragging ? 0.5 : 1, backgroundColor: dragOver ? 'rgba(25, 118, 210, 0.08)' : 'transparent', borderLeft: dragOver ? '2px solid #1976d2' : 'none', padding: dragOver ? '0 0 0 -2px' : '0', width: '100%', height: '100%', minWidth: '0', '&:active': {
188
189
  cursor: draggable ? 'grabbing' : 'pointer',
190
+ }, '.header-content': {
191
+ display: 'block',
192
+ flex: 1,
193
+ minWidth: 0,
194
+ overflow: 'hidden',
195
+ whiteSpace: 'nowrap',
196
+ textOverflow: 'ellipsis',
189
197
  } }, containerSx),
190
198
  draggable: draggable,
191
199
  onDragStart: handleDragStart,
@@ -199,8 +207,9 @@ function DraggableHeader(props) {
199
207
  if (!draggable && !enableSorting) {
200
208
  return (0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext());
201
209
  }
202
- return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({}, mergedContainerProps, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "span", sx: {
210
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({}, mergedContainerProps, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "span", className: 'header-wrapper', sx: {
203
211
  display: 'inline-flex',
204
212
  gap: 1,
205
- }, children: [(0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext()), getSortIcon()] }) })));
213
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: "span", className: 'header-content', children: (0, react_table_1.flexRender)(header.column.columnDef.header, header.getContext()) }), getSortIcon()] }) })));
206
214
  }
215
+ exports.DraggableHeaderMemo = react_1.default.memo(DraggableHeader);
@@ -23,11 +23,13 @@ function TableHeader(props) {
23
23
  }, headerSlotProps, otherProps);
24
24
  const mergedHeaderRowProps = (0, slot_helpers_1.mergeSlotProps)({}, headerRowSlotProps, headerRowProps || {});
25
25
  const renderHeaderCell = (header) => {
26
+ var _a;
26
27
  const isPinned = header.column.getIsPinned();
27
28
  const pinnedPosition = isPinned ? header.column.getStart('left') : undefined;
28
29
  const pinnedRightPosition = isPinned === 'right' ? header.column.getAfter('right') : undefined;
29
30
  const alignment = (0, utils_1.getColumnAlignment)(header.column.columnDef);
30
31
  const enableSorting = header.column.getCanSort();
32
+ const wrapText = (_a = header.column.columnDef.wrapText) !== null && _a !== void 0 ? _a : false;
31
33
  const mergedHeaderCellProps = (0, slot_helpers_1.mergeSlotProps)({
32
34
  align: alignment,
33
35
  sx: Object.assign({}, (0, utils_1.getPinnedColumnStyle)({
@@ -39,6 +41,7 @@ function TableHeader(props) {
39
41
  pinnedRightPosition,
40
42
  zIndex: isPinned ? 10 : 1,
41
43
  disableStickyHeader: enableStickyHeader,
44
+ wrapText,
42
45
  })),
43
46
  }, headerCellSlotProps, headerCellProps || {});
44
47
  const mergedResizeHandleProps = (0, slot_helpers_1.mergeSlotProps)({
@@ -8,6 +8,8 @@ export interface DataTableRowProps<T> extends TableRowProps {
8
8
  isOdd?: boolean;
9
9
  renderSubComponent?: (row: Row<T>) => ReactNode;
10
10
  disableStickyHeader?: boolean;
11
+ onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, row: Row<T>) => void;
12
+ selectOnRowClick?: boolean;
11
13
  cellProps?: TableCellProps;
12
14
  expandedRowProps?: TableRowProps;
13
15
  expandedCellProps?: TableCellProps;
@@ -7,30 +7,62 @@ const material_1 = require("@mui/material");
7
7
  const react_table_1 = require("@tanstack/react-table");
8
8
  const utils_1 = require("../../utils");
9
9
  const slot_helpers_1 = require("../../utils/slot-helpers");
10
+ const data_table_context_1 = require("../../contexts/data-table-context");
10
11
  function DataTableRow(props) {
11
- const { row, enableHover = true, enableStripes = false, isOdd = false, renderSubComponent, disableStickyHeader = false, cellProps, expandedRowProps, expandedCellProps, containerSx, expandedContainerSx, slots, slotProps } = props, otherProps = tslib_1.__rest(props, ["row", "enableHover", "enableStripes", "isOdd", "renderSubComponent", "disableStickyHeader", "cellProps", "expandedRowProps", "expandedCellProps", "containerSx", "expandedContainerSx", "slots", "slotProps"]);
12
+ var _a;
13
+ const { row, enableHover = true, enableStripes = false, isOdd = false, renderSubComponent, disableStickyHeader = false, onRowClick, selectOnRowClick = false, cellProps, expandedRowProps, expandedCellProps, containerSx, expandedContainerSx, slots, slotProps } = props, otherProps = tslib_1.__rest(props, ["row", "enableHover", "enableStripes", "isOdd", "renderSubComponent", "disableStickyHeader", "onRowClick", "selectOnRowClick", "cellProps", "expandedRowProps", "expandedCellProps", "containerSx", "expandedContainerSx", "slots", "slotProps"]);
14
+ const { table } = (0, data_table_context_1.useDataTableContext)();
12
15
  const cellSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'cell');
13
16
  const expandedRowSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'expandedRow');
14
17
  const rowSlotProps = (0, slot_helpers_1.extractSlotProps)(slotProps, 'row');
15
18
  const CellSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'cell', material_1.TableCell);
16
19
  const ExpandedRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'expandedRow', material_1.TableRow);
17
20
  const TableRowSlot = (0, slot_helpers_1.getSlotComponent)(slots, 'row', material_1.TableRow);
21
+ const handleRowClick = (event) => {
22
+ const target = event.target;
23
+ const isCheckboxClick = target.closest('input[type="checkbox"]') !== null;
24
+ const isButtonClick = target.closest('button') !== null;
25
+ const isLinkClick = target.closest('a') !== null;
26
+ if (selectOnRowClick && !isCheckboxClick && !isButtonClick && !isLinkClick && (table === null || table === void 0 ? void 0 : table.toggleRowSelected)) {
27
+ table.toggleRowSelected(row.id);
28
+ }
29
+ if (onRowClick) {
30
+ onRowClick(event, row);
31
+ }
32
+ };
18
33
  const mergedRowProps = (0, slot_helpers_1.mergeSlotProps)({
19
34
  hover: enableHover,
20
- sx: Object.assign({ backgroundColor: enableStripes && isOdd ? 'action.hover' : 'transparent' }, containerSx),
35
+ selected: !!((_a = table === null || table === void 0 ? void 0 : table.getIsRowSelected) === null || _a === void 0 ? void 0 : _a.call(table, row.id)),
36
+ onClick: (onRowClick || selectOnRowClick) ? handleRowClick : undefined,
37
+ sx: (theme) => (Object.assign(Object.assign(Object.assign(Object.assign({ '--row-bg': enableStripes && isOdd
38
+ ? theme.palette.action.hover
39
+ : theme.palette.background.paper, backgroundColor: 'var(--row-bg)' }, (enableHover && {
40
+ '&:hover': { '--row-bg': theme.palette.action.hover },
41
+ })), { [`&.${material_1.tableRowClasses.selected}`]: {
42
+ '--row-bg': theme.palette.action.selected,
43
+ backgroundColor: 'var(--row-bg)',
44
+ } }), ((onRowClick || selectOnRowClick) && {
45
+ cursor: 'pointer',
46
+ })), containerSx)),
21
47
  }, rowSlotProps, otherProps);
22
48
  const mergedExpandedRowProps = (0, slot_helpers_1.mergeSlotProps)({
23
49
  sx: expandedContainerSx,
24
50
  }, expandedRowSlotProps, expandedRowProps || {});
25
51
  return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableRowSlot, Object.assign({}, mergedRowProps, { children: row.getVisibleCells().map(cell => {
52
+ var _a, _b;
26
53
  const isPinned = cell.column.getIsPinned();
27
54
  const pinnedPosition = isPinned ? cell.column.getStart('left') : undefined;
28
55
  const pinnedRightPosition = isPinned === 'right' ? cell.column.getAfter('right') : undefined;
29
56
  const alignment = (0, utils_1.getColumnAlignment)(cell.column.columnDef);
57
+ const minSize = (_a = cell.column.columnDef) === null || _a === void 0 ? void 0 : _a.minSize;
58
+ const maxSize = cell.column.columnDef.maxSize;
59
+ const wrapText = (_b = cell.column.columnDef.wrapText) !== null && _b !== void 0 ? _b : false;
30
60
  const mergedCellProps = (0, slot_helpers_1.mergeSlotProps)({
31
61
  align: alignment,
32
62
  sx: Object.assign({}, (0, utils_1.getPinnedColumnStyle)({
33
63
  width: cell.column.getSize() || 'auto',
64
+ minWidth: minSize !== undefined ? minSize : undefined,
65
+ maxWidth: maxSize !== undefined ? maxSize : undefined,
34
66
  isPinned,
35
67
  pinnedPosition,
36
68
  pinnedRightPosition,
@@ -38,6 +70,7 @@ function DataTableRow(props) {
38
70
  disableStickyHeader,
39
71
  isLastLeftPinnedColumn: isPinned === 'left' && cell.column.getIsLastColumn('left'),
40
72
  isFirstRightPinnedColumn: isPinned === 'right' && cell.column.getIsFirstColumn('right'),
73
+ wrapText,
41
74
  })),
42
75
  }, cellSlotProps, cellProps || {});
43
76
  return ((0, jsx_runtime_1.jsx)(CellSlot, Object.assign({}, mergedCellProps, { children: (0, react_table_1.flexRender)(cell.column.columnDef.cell, cell.getContext()) }), cell.id));
@@ -41,7 +41,7 @@ const DEFAULT_INITIAL_STATE = {
41
41
  pendingLogic: 'AND',
42
42
  },
43
43
  };
44
- 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', onColumnSizingChange, enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, onColumnVisibilityChange, enableColumnVisibility = true, 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, enableTableSizeControl = true, enableExport = false, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onPaginationChange, onGlobalFilterChange, slots = {}, slotProps = {}, logging, }, ref) {
44
+ 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, onRowClick, selectOnRowClick = false, enableBulkActions = false, bulkActions, enableColumnResizing = false, columnResizeMode = 'onChange', onColumnSizingChange, enableColumnDragging = false, onColumnDragEnd, enableColumnPinning = false, onColumnPinningChange, onColumnVisibilityChange, enableColumnVisibility = true, 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, enableTableSizeControl = true, enableExport = false, enableReset = true, loading = false, emptyMessage = 'No data available', skeletonRows = 5, onColumnFiltersChange, onPaginationChange, onGlobalFilterChange, slots = {}, slotProps = {}, logging, }, ref) {
45
45
  var _a;
46
46
  const isServerMode = dataMode === 'server';
47
47
  const isServerPagination = paginationMode === 'server' || isServerMode;
@@ -70,7 +70,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
70
70
  }
71
71
  return config;
72
72
  }, [initialState, logger]);
73
- console.log('initialStateConfig', initialStateConfig);
74
73
  const [sorting, setSorting] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || DEFAULT_INITIAL_STATE.sorting);
75
74
  const [pagination, setPagination] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.pagination) || DEFAULT_INITIAL_STATE.pagination);
76
75
  const [globalFilter, setGlobalFilter] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.globalFilter) || DEFAULT_INITIAL_STATE.globalFilter);
@@ -80,6 +79,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
80
79
  const [tableSize, setTableSize] = (0, react_1.useState)(initialTableSize || 'medium');
81
80
  const [columnOrder, setColumnOrder] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder) || DEFAULT_INITIAL_STATE.columnOrder);
82
81
  const [columnPinning, setColumnPinning] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnPinning) || DEFAULT_INITIAL_STATE.columnPinning);
82
+ const [columnVisibility, setColumnVisibility] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnVisibility) || DEFAULT_INITIAL_STATE.columnVisibility);
83
+ const [columnSizing, setColumnSizing] = (0, react_1.useState)((initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing) || DEFAULT_INITIAL_STATE.columnSizing);
83
84
  const [serverData, setServerData] = (0, react_1.useState)(null);
84
85
  const [serverTotal, setServerTotal] = (0, react_1.useState)(0);
85
86
  const [exportController, setExportController] = (0, react_1.useState)(null);
@@ -154,7 +155,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
154
155
  pagination,
155
156
  columnFilter,
156
157
  sorting }, overrides);
157
- console.log('filters', filters);
158
158
  if (logger.isLevelEnabled('info')) {
159
159
  logger.info('Requesting data', { filters });
160
160
  }
@@ -218,7 +218,9 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
218
218
  sorting,
219
219
  pagination,
220
220
  columnOrder,
221
- columnPinning }, overrides);
221
+ columnPinning,
222
+ columnVisibility,
223
+ columnSizing }, overrides);
222
224
  if (logger.isLevelEnabled('debug')) {
223
225
  logger.debug('Emitting tableStateChange', currentState);
224
226
  }
@@ -231,6 +233,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
231
233
  pagination,
232
234
  columnOrder,
233
235
  columnPinning,
236
+ columnVisibility,
237
+ columnSizing,
234
238
  logger,
235
239
  ]);
236
240
  const handleSortingChange = (0, react_1.useCallback)((updaterOrValue) => {
@@ -296,12 +300,10 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
296
300
  }
297
301
  }, [onColumnPinningChange, columnPinning]);
298
302
  const handleColumnVisibilityChange = (0, react_1.useCallback)((updater) => {
299
- var _a, _b;
300
- const tableInstance = (_b = (_a = internalApiRef.current) === null || _a === void 0 ? void 0 : _a.table) === null || _b === void 0 ? void 0 : _b.getTable();
301
- if (!tableInstance)
302
- return;
303
- const currentVisibility = tableInstance.getState().columnVisibility;
304
- const newVisibility = typeof updater === 'function' ? updater(currentVisibility) : updater;
303
+ const newVisibility = typeof updater === 'function'
304
+ ? updater(columnVisibility)
305
+ : updater;
306
+ setColumnVisibility(newVisibility);
305
307
  if (onColumnVisibilityChange) {
306
308
  setTimeout(() => {
307
309
  onColumnVisibilityChange(newVisibility);
@@ -312,14 +314,12 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
312
314
  tableStateChange({ columnVisibility: newVisibility });
313
315
  }, 0);
314
316
  }
315
- }, [onColumnVisibilityChange, onDataStateChange, tableStateChange]);
317
+ }, [onColumnVisibilityChange, onDataStateChange, tableStateChange, columnVisibility]);
316
318
  const handleColumnSizingChange = (0, react_1.useCallback)((updater) => {
317
- var _a, _b;
318
- const tableInstance = (_b = (_a = internalApiRef.current) === null || _a === void 0 ? void 0 : _a.table) === null || _b === void 0 ? void 0 : _b.getTable();
319
- if (!tableInstance)
320
- return;
321
- const currentSizing = tableInstance.getState().columnSizing;
322
- const newSizing = typeof updater === 'function' ? updater(currentSizing) : updater;
319
+ const newSizing = typeof updater === 'function'
320
+ ? updater(columnSizing)
321
+ : updater;
322
+ setColumnSizing(newSizing);
323
323
  if (onColumnSizingChange) {
324
324
  setTimeout(() => {
325
325
  onColumnSizingChange(newSizing);
@@ -330,7 +330,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
330
330
  tableStateChange({ columnSizing: newSizing });
331
331
  }, 0);
332
332
  }
333
- }, [onColumnSizingChange, onDataStateChange, tableStateChange]);
333
+ }, [onColumnSizingChange, onDataStateChange, tableStateChange, columnSizing]);
334
334
  const handlePaginationChange = (0, react_1.useCallback)((updater) => {
335
335
  const newPagination = typeof updater === 'function' ? updater(pagination) : updater;
336
336
  if (logger.isLevelEnabled('debug')) {
@@ -340,7 +340,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
340
340
  serverSide: isServerMode || isServerPagination,
341
341
  });
342
342
  }
343
- console.log('newPagination', newPagination);
344
343
  setPagination(newPagination);
345
344
  onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
346
345
  if (logger.isLevelEnabled('debug')) {
@@ -449,7 +448,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
449
448
  }
450
449
  }, 0);
451
450
  }, [isServerFiltering, fetchData, tableStateChange]);
452
- const table = (0, react_table_1.useReactTable)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ _features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature], data: tableData, columns: enhancedColumns, initialState: Object.assign({}, DEFAULT_INITIAL_STATE), state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (enableSorting ? { sorting } : {})), (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnFilter ? { columnFilter } : {})), (enableRowSelection ? { selectionState } : {})), selectMode: selectMode, enableAdvanceSelection: !!enableRowSelection, isRowSelectable: isRowSelectable }, (enableRowSelection ? { onSelectionStateChange: handleSelectionStateChange } : {})), { enableAdvanceColumnFilter: enableColumnFilter, onColumnFilterChange: onColumnFilterChangeHandler, onColumnFilterApply: onColumnFilterApplyHandler }), (enableSorting ? { onSortingChange: handleSortingChange } : {})), (enablePagination ? { onPaginationChange: handlePaginationChange } : {})), (enableRowSelection ? { onRowSelectionChange: handleSelectionStateChange } : {})), (enableGlobalFilter ? { onGlobalFilterChange: handleGlobalFilterChange } : {})), (enableExpanding ? { onExpandedChange: setExpanded } : {})), (enableColumnDragging ? { onColumnOrderChange: handleColumnOrderChange } : {})), (enableColumnPinning ? { onColumnPinningChange: handleColumnPinningChange } : {})), (enableColumnVisibility ? { onColumnVisibilityChange: handleColumnVisibilityChange } : {})), (enableColumnResizing ? { onColumnSizingChange: handleColumnSizingChange } : {})), { getCoreRowModel: (0, react_table_1.getCoreRowModel)() }), (enableSorting ? { getSortedRowModel: (0, react_table_1.getSortedRowModel)() } : {})), (enableColumnFilter ? { getFilteredRowModel: (0, column_filter_feature_1.getCombinedFilteredRowModel)() } : {})), (enablePagination ? { getPaginationRowModel: (0, react_table_1.getPaginationRowModel)() } : {})), { enableSorting: enableSorting, manualSorting: isServerSorting, manualFiltering: isServerFiltering, enableColumnResizing: enableColumnResizing, columnResizeMode: columnResizeMode, enableColumnPinning: enableColumnPinning }), (enableExpanding ? { getRowCanExpand: getRowCanExpand } : {})), { manualPagination: isServerPagination, autoResetPageIndex: false, rowCount: tableTotalRow, getRowId: (row, index) => (0, utils_1.generateRowId)(row, index, idKey), debugAll: false }));
451
+ const table = (0, react_table_1.useReactTable)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ _features: [column_filter_feature_1.ColumnFilterFeature, features_1.SelectionFeature], data: tableData, columns: enhancedColumns, initialState: Object.assign({}, DEFAULT_INITIAL_STATE), state: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (enableSorting ? { sorting } : {})), (enablePagination ? { pagination } : {})), (enableGlobalFilter ? { globalFilter } : {})), (enableExpanding ? { expanded } : {})), (enableColumnDragging ? { columnOrder } : {})), (enableColumnPinning ? { columnPinning } : {})), (enableColumnVisibility ? { columnVisibility } : {})), (enableColumnResizing ? { columnSizing } : {})), (enableColumnFilter ? { columnFilter } : {})), (enableRowSelection ? { selectionState } : {})), selectMode: selectMode, enableAdvanceSelection: !!enableRowSelection, isRowSelectable: isRowSelectable }, (enableRowSelection ? { onSelectionStateChange: handleSelectionStateChange } : {})), { enableAdvanceColumnFilter: enableColumnFilter, onColumnFilterChange: onColumnFilterChangeHandler, onColumnFilterApply: onColumnFilterApplyHandler }), (enableSorting ? { onSortingChange: handleSortingChange } : {})), (enablePagination ? { onPaginationChange: handlePaginationChange } : {})), (enableRowSelection ? { onRowSelectionChange: handleSelectionStateChange } : {})), (enableGlobalFilter ? { onGlobalFilterChange: handleGlobalFilterChange } : {})), (enableExpanding ? { onExpandedChange: setExpanded } : {})), (enableColumnDragging ? { onColumnOrderChange: handleColumnOrderChange } : {})), (enableColumnPinning ? { onColumnPinningChange: handleColumnPinningChange } : {})), (enableColumnVisibility ? { onColumnVisibilityChange: handleColumnVisibilityChange } : {})), (enableColumnResizing ? { onColumnSizingChange: handleColumnSizingChange } : {})), { getCoreRowModel: (0, react_table_1.getCoreRowModel)() }), (enableSorting ? { getSortedRowModel: (0, react_table_1.getSortedRowModel)() } : {})), (enableColumnFilter ? { getFilteredRowModel: (0, column_filter_feature_1.getCombinedFilteredRowModel)() } : {})), (enablePagination ? { getPaginationRowModel: (0, react_table_1.getPaginationRowModel)() } : {})), { enableSorting: enableSorting, manualSorting: isServerSorting, manualFiltering: isServerFiltering, enableColumnResizing: enableColumnResizing, columnResizeMode: columnResizeMode, enableColumnPinning: enableColumnPinning }), (enableExpanding ? { getRowCanExpand: getRowCanExpand } : {})), { manualPagination: isServerPagination, autoResetPageIndex: false, rowCount: tableTotalRow, getRowId: (row, index) => (0, utils_1.generateRowId)(row, index, idKey), debugAll: false }));
453
452
  const rows = ((_a = table.getRowModel()) === null || _a === void 0 ? void 0 : _a.rows) || [];
454
453
  const rowVirtualizer = (0, react_virtual_1.useVirtualizer)({
455
454
  count: rows.length,
@@ -468,8 +467,6 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
468
467
  const newPagination = { pageIndex: 0, pageSize: pagination.pageSize };
469
468
  setPagination(newPagination);
470
469
  onPaginationChange === null || onPaginationChange === void 0 ? void 0 : onPaginationChange(newPagination);
471
- console.log('newPagination', newPagination);
472
- console.log('onPaginationChange', onPaginationChange);
473
470
  return newPagination;
474
471
  };
475
472
  const handleColumnReorder = (0, react_1.useCallback)((draggedColumnId, targetColumnId) => {
@@ -1209,7 +1206,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
1209
1206
  const row = rows[virtualRow.index];
1210
1207
  if (!row)
1211
1208
  return null;
1212
- return ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: virtualRow.index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, slots: slots, slotProps: slotProps }, row.id));
1209
+ return ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: virtualRow.index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, onRowClick: onRowClick, selectOnRowClick: selectOnRowClick, slots: slots, slotProps: slotProps }, row.id));
1213
1210
  }), virtualItems.length > 0 && ((0, jsx_runtime_1.jsx)("tr", { children: (0, jsx_runtime_1.jsx)("td", { colSpan: table.getAllColumns().length, style: {
1214
1211
  height: `${rowVirtualizer.getTotalSize() -
1215
1212
  ((_d = (_c = virtualItems[virtualItems.length - 1]) === null || _c === void 0 ? void 0 : _c.end) !== null && _d !== void 0 ? _d : 0)}px`,
@@ -1217,7 +1214,7 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
1217
1214
  border: 0,
1218
1215
  } }) }))] }));
1219
1216
  }
1220
- return rows.map((row, index) => ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, slots: slots, slotProps: slotProps }, row.id)));
1217
+ return rows.map((row, index) => ((0, jsx_runtime_1.jsx)(rows_1.DataTableRow, { row: row, enableHover: enableHover, enableStripes: enableStripes, isOdd: index % 2 === 1, renderSubComponent: renderSubComponent, disableStickyHeader: enableStickyHeaderOrFooter, onRowClick: onRowClick, selectOnRowClick: selectOnRowClick, slots: slots, slotProps: slotProps }, row.id)));
1221
1218
  }, [
1222
1219
  tableLoading,
1223
1220
  rows,
@@ -1233,6 +1230,8 @@ exports.DataTable = (0, react_1.forwardRef)(function DataTable({ initialState, c
1233
1230
  enableStripes,
1234
1231
  renderSubComponent,
1235
1232
  enableStickyHeaderOrFooter,
1233
+ onRowClick,
1234
+ selectOnRowClick,
1236
1235
  slots,
1237
1236
  ]);
1238
1237
  const handleCancelExport = (0, react_1.useCallback)(() => {
@@ -53,6 +53,8 @@ export interface DataTableProps<T> {
53
53
  id: string;
54
54
  }) => boolean;
55
55
  onSelectionChange?: (selection: SelectionState) => void;
56
+ onRowClick?: (event: React.MouseEvent<HTMLTableRowElement>, row: Row<T>) => void;
57
+ selectOnRowClick?: boolean;
56
58
  enableBulkActions?: boolean;
57
59
  bulkActions?: (selectionState: SelectionState) => ReactNode;
58
60
  enableColumnResizing?: boolean;
@@ -56,7 +56,8 @@ function ColumnPinningControl(props = {}) {
56
56
  return column.id;
57
57
  };
58
58
  const handleUnpinAll = (0, react_1.useCallback)(() => {
59
- table.setColumnPinning(table.initialState.columnPinning || {});
59
+ var _a;
60
+ table === null || table === void 0 ? void 0 : table.setColumnPinning(((_a = table === null || table === void 0 ? void 0 : table.initialState) === null || _a === void 0 ? void 0 : _a.columnPinning) || {});
60
61
  }, [table]);
61
62
  const userPinnedLeft = (((_a = columnPinning.left) === null || _a === void 0 ? void 0 : _a.filter((id) => allColumns.some((column) => column.id === id))) || []);
62
63
  const userPinnedRight = (((_b = columnPinning.right) === null || _b === void 0 ? void 0 : _b.filter((id) => allColumns.some((column) => column.id === id))) || []);
@@ -151,35 +151,30 @@ function ServerSideFetchingExample() {
151
151
  id: 'name',
152
152
  accessorKey: 'name',
153
153
  header: 'Name',
154
- size: 200,
155
154
  enableGlobalFilter: true,
156
155
  },
157
156
  {
158
157
  id: 'email',
159
158
  accessorKey: 'email',
160
159
  header: 'Email',
161
- size: 250,
162
160
  enableGlobalFilter: true,
163
161
  },
164
162
  {
165
163
  id: 'department',
166
164
  accessorKey: 'department',
167
165
  header: 'Department',
168
- size: 150,
169
166
  enableGlobalFilter: true,
170
167
  },
171
168
  {
172
169
  id: 'role',
173
170
  accessorKey: 'role',
174
171
  header: 'Role',
175
- size: 120,
176
172
  enableGlobalFilter: true,
177
173
  },
178
174
  {
179
175
  id: 'salary',
180
176
  accessorKey: 'salary',
181
177
  header: 'Salary',
182
- size: 120,
183
178
  accessorFn: (row) => `$${row.salary.toLocaleString()}`,
184
179
  hideInExport: true,
185
180
  },
@@ -187,7 +182,6 @@ function ServerSideFetchingExample() {
187
182
  id: 'isActive',
188
183
  accessorKey: 'isActive',
189
184
  header: 'Status',
190
- size: 100,
191
185
  accessorFn: (row) => row.isActive ? 'Active' : 'Inactive',
192
186
  cell: ({ getValue }) => ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: getValue() ? 'Active' : 'Inactive', color: getValue() ? 'success' : 'default', size: "small" })),
193
187
  },
@@ -195,7 +189,6 @@ function ServerSideFetchingExample() {
195
189
  id: 'joinDate',
196
190
  accessorKey: 'joinDate',
197
191
  header: 'Join Date',
198
- size: 120,
199
192
  accessorFn: (row) => new Date(row.joinDate).toLocaleDateString(),
200
193
  },
201
194
  ];
@@ -28,30 +28,28 @@ const columns = [
28
28
  {
29
29
  accessorKey: 'name',
30
30
  header: 'Product Name',
31
- size: 180,
32
31
  },
33
32
  {
34
33
  accessorKey: 'category',
35
34
  header: 'Category',
36
- size: 120,
37
35
  cell: ({ getValue }) => ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: getValue(), size: "small", variant: "outlined", color: "primary" })),
38
36
  },
39
37
  {
40
38
  accessorKey: 'price',
41
39
  header: 'Price',
42
- size: 100,
43
40
  cell: ({ getValue }) => `$${getValue().toFixed(2)}`,
44
41
  },
45
42
  {
46
43
  accessorKey: 'inStock',
47
44
  header: 'In Stock',
48
- size: 100,
49
45
  cell: ({ getValue }) => ((0, jsx_runtime_1.jsx)(material_1.Chip, { label: getValue() ? 'Yes' : 'No', color: getValue() ? 'success' : 'error', size: "small" })),
50
46
  },
51
47
  {
52
48
  accessorKey: 'rating',
53
49
  header: 'Rating',
54
50
  size: 100,
51
+ minSize: 100,
52
+ maxSize: 100,
55
53
  cell: ({ getValue }) => `⭐ ${getValue().toFixed(1)}`,
56
54
  },
57
55
  ];
@@ -12,6 +12,7 @@ declare module '@tanstack/table-core' {
12
12
  align?: 'left' | 'center' | 'right';
13
13
  filterable?: boolean;
14
14
  hideInExport?: boolean;
15
+ wrapText?: boolean;
15
16
  editComponent?: React.ComponentType<{
16
17
  value: any;
17
18
  onChange: (value: any) => void;
@@ -62,6 +62,8 @@ export interface ChunkProcessingConfig {
62
62
  }
63
63
  export interface PinnedColumnStyleOptions {
64
64
  width?: number | string;
65
+ minWidth?: number;
66
+ maxWidth?: number;
65
67
  isPinned?: 'left' | 'right' | false;
66
68
  pinnedPosition?: number;
67
69
  pinnedRightPosition?: number;
@@ -69,6 +71,7 @@ export interface PinnedColumnStyleOptions {
69
71
  disableStickyHeader?: boolean;
70
72
  isLastLeftPinnedColumn?: boolean;
71
73
  isFirstRightPinnedColumn?: boolean;
74
+ wrapText?: boolean;
72
75
  }
73
76
  export interface SimpleExportOptions {
74
77
  filename?: string;
@@ -2,5 +2,5 @@ import { DataTableColumn } from '../types';
2
2
  export interface SelectionColumnConfig<T> {
3
3
  multiSelect?: boolean;
4
4
  }
5
- export declare const createSelectionColumn: <T>(config: Partial<DataTableColumn<T>> & SelectionColumnConfig<T>) => DataTableColumn<T>;
5
+ export declare const createSelectionColumn: <T>(config: Partial<DataTableColumn<T>> & SelectionColumnConfig<T>) => DataTableColumn<T, any>;
6
6
  export declare const createExpandingColumn: <T>(config: Partial<DataTableColumn<T>>) => DataTableColumn<T>;
@@ -5,7 +5,7 @@ const icons_material_1 = require("@mui/icons-material");
5
5
  const material_1 = require("@mui/material");
6
6
  const react_1 = require("react");
7
7
  const types_1 = require("../types");
8
- const createSelectionColumn = (config) => (Object.assign({ id: types_1.DEFAULT_SELECTION_COLUMN_NAME, size: 60, align: 'center', filterable: false, enableResizing: false, enableSorting: false, enableHiding: false, enablePinning: false, hideInExport: true, header: ({ table }) => {
8
+ const createSelectionColumn = (config) => (Object.assign({ id: types_1.DEFAULT_SELECTION_COLUMN_NAME, size: 60, minSize: 60, align: 'center', filterable: false, enableResizing: false, enableSorting: false, enableHiding: false, enablePinning: false, hideInExport: true, header: ({ table }) => {
9
9
  var _a, _b;
10
10
  if (!config.multiSelect)
11
11
  return null;
@@ -44,7 +44,7 @@ const createSelectionColumn = (config) => (Object.assign({ id: types_1.DEFAULT_S
44
44
  });
45
45
  } }, config));
46
46
  exports.createSelectionColumn = createSelectionColumn;
47
- const createExpandingColumn = (config) => (Object.assign({ id: types_1.DEFAULT_EXPANDING_COLUMN_NAME, size: 60, align: 'center', filterable: false, enableResizing: false, enableSorting: false, enableHiding: false, enablePinning: false, hideInExport: true, header: '', cell: ({ row }) => (0, react_1.createElement)(material_1.IconButton, {
47
+ const createExpandingColumn = (config) => (Object.assign({ id: types_1.DEFAULT_EXPANDING_COLUMN_NAME, size: 60, minSize: 60, align: 'center', filterable: false, enableResizing: false, enableSorting: false, enableHiding: false, enablePinning: false, hideInExport: true, header: '', cell: ({ row }) => (0, react_1.createElement)(material_1.IconButton, {
48
48
  onClick: row.getToggleExpandedHandler(),
49
49
  size: 'small',
50
50
  sx: { p: 0 },
@@ -1,14 +1,58 @@
1
1
  import type { DataTableColumn, PinnedColumnStyleOptions } from '../types';
2
2
  export declare function getPinnedColumnStyle(options: PinnedColumnStyleOptions): {
3
+ backgroundColor: (theme: any) => any;
4
+ backgroundImage: (theme: any) => string;
3
5
  boxShadow: string;
4
- backgroundColor: string;
5
6
  left?: number;
6
7
  right?: number;
7
8
  zIndex?: number;
9
+ whiteSpace: "normal";
10
+ wordBreak: "break-word";
11
+ overflow: "visible";
12
+ textOverflow?: undefined;
13
+ maxWidth: string | number;
14
+ minWidth: number;
15
+ width: string | number;
16
+ } | {
17
+ backgroundColor: (theme: any) => string;
18
+ boxShadow: string;
19
+ left?: number;
20
+ right?: number;
21
+ zIndex?: number;
22
+ whiteSpace: "normal";
23
+ wordBreak: "break-word";
24
+ overflow: "visible";
25
+ textOverflow?: undefined;
26
+ maxWidth: string | number;
27
+ minWidth: number;
28
+ width: string | number;
29
+ } | {
30
+ backgroundColor: (theme: any) => any;
31
+ backgroundImage: (theme: any) => string;
32
+ boxShadow: string;
33
+ left?: number;
34
+ right?: number;
35
+ zIndex?: number;
36
+ overflow: "hidden";
37
+ whiteSpace: "nowrap";
38
+ textOverflow: "ellipsis";
39
+ wordBreak?: undefined;
40
+ maxWidth: string | number;
41
+ minWidth: number;
8
42
  width: string | number;
43
+ } | {
44
+ backgroundColor: (theme: any) => string;
45
+ boxShadow: string;
46
+ left?: number;
47
+ right?: number;
48
+ zIndex?: number;
49
+ overflow: "hidden";
50
+ whiteSpace: "nowrap";
51
+ textOverflow: "ellipsis";
52
+ wordBreak?: undefined;
9
53
  maxWidth: string | number;
10
- overflow: string;
11
- whiteSpace: string;
54
+ minWidth: number;
55
+ width: string | number;
12
56
  };
13
57
  export declare const tableCellStyles: {
14
58
  readonly sticky: {
@@ -3,17 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tableRowStyles = exports.tableCellStyles = void 0;
4
4
  exports.getPinnedColumnStyle = getPinnedColumnStyle;
5
5
  exports.getColumnAlignment = getColumnAlignment;
6
- const getBoxShadow = (isPinned, isLastLeftPinnedColumn, isFirstRightPinnedColumn) => {
7
- if (isPinned === 'left' && isLastLeftPinnedColumn) {
8
- return '1px 0 3px rgba(0, 0, 0, 0.12)';
9
- }
10
- if (isPinned === 'right' && isFirstRightPinnedColumn) {
11
- return '-1px 0 3px rgba(0, 0, 0, 0.12)';
12
- }
13
- return 'none';
14
- };
15
6
  function getPinnedColumnStyle(options) {
16
- const { width = 'auto', isPinned, pinnedPosition, pinnedRightPosition, isLastLeftPinnedColumn, isFirstRightPinnedColumn, zIndex = 1, disableStickyHeader = false, } = options;
7
+ const { width = 'auto', minWidth, maxWidth, isPinned, pinnedPosition, pinnedRightPosition, isLastLeftPinnedColumn, isFirstRightPinnedColumn, zIndex = 1, disableStickyHeader = false, wrapText = false, } = options;
17
8
  const needsPinnedPositioning = isPinned;
18
9
  const shouldBeSticky = isPinned;
19
10
  let positionStyle = {};
@@ -23,13 +14,31 @@ function getPinnedColumnStyle(options) {
23
14
  else if (!disableStickyHeader) {
24
15
  positionStyle = { position: 'relative' };
25
16
  }
26
- return Object.assign(Object.assign(Object.assign(Object.assign({ width, maxWidth: width, overflow: 'hidden', whiteSpace: 'nowrap' }, positionStyle), (needsPinnedPositioning ? {
17
+ const textWrappingStyles = wrapText
18
+ ? {
19
+ whiteSpace: 'normal',
20
+ wordBreak: 'break-word',
21
+ overflow: 'visible',
22
+ }
23
+ : {
24
+ overflow: 'hidden',
25
+ whiteSpace: 'nowrap',
26
+ textOverflow: 'ellipsis',
27
+ };
28
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ width }, (minWidth !== undefined && { minWidth })), (maxWidth !== undefined ? { maxWidth } : { maxWidth: width })), textWrappingStyles), positionStyle), (needsPinnedPositioning ? {
27
29
  left: isPinned === 'left' ? pinnedPosition : undefined,
28
30
  right: isPinned === 'right' ? pinnedRightPosition : undefined,
29
31
  zIndex,
30
- } : {})), (isPinned && {
31
- backgroundColor: 'background.paper',
32
- })), { boxShadow: getBoxShadow(isPinned, !!isLastLeftPinnedColumn, !!isFirstRightPinnedColumn) });
32
+ } : {})), { boxShadow: isPinned === 'left' && isLastLeftPinnedColumn
33
+ ? 'inset -1px 0 0 var(--palette-TableCell-border), 6px 0 6px -4px rgba(0,0,0,.18)'
34
+ : isPinned === 'right' && isFirstRightPinnedColumn
35
+ ? 'inset 1px 0 0 var(--palette-TableCell-border), -6px 0 6px -4px rgba(0,0,0,.18)'
36
+ : undefined }), (isPinned ? {
37
+ backgroundColor: (theme) => theme.palette.background.paper,
38
+ backgroundImage: (theme) => `linear-gradient(var(--row-bg, ${theme.palette.background.paper}), var(--row-bg, ${theme.palette.background.paper}))`,
39
+ } : {
40
+ backgroundColor: (theme) => `var(--row-bg, ${theme.palette.background.paper})`,
41
+ }));
33
42
  }
34
43
  exports.tableCellStyles = {
35
44
  sticky: {