@insticc/react-datagrid-2 1.1.27 → 1.1.29
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/README.md +129 -1
- package/build/wrapper/index.js +74 -28
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -340,6 +340,53 @@ actions={[
|
|
|
340
340
|
]}
|
|
341
341
|
```
|
|
342
342
|
|
|
343
|
+
#### `filterActions`
|
|
344
|
+
- **Type:** `Array<FilterActionObject>`
|
|
345
|
+
- **Default:** `null`
|
|
346
|
+
- **Description:** Array of toggle filter action buttons displayed in the toolbar for showing/hiding data based on filters
|
|
347
|
+
- **Filter Action Object Properties:**
|
|
348
|
+
- `name` (string): Button label
|
|
349
|
+
- `function` (function, required): Callback when button is toggled - receives current state
|
|
350
|
+
- `state` (boolean): Current filter state (true = filter active/hidden, false = filter inactive/shown)
|
|
351
|
+
- `key` (string): Unique React key (defaults to name)
|
|
352
|
+
- `tooltip` (string): Tooltip text on hover
|
|
353
|
+
- `disabled` (boolean): Manually disable the button
|
|
354
|
+
- `visible` (boolean): Show/hide the button (default: true)
|
|
355
|
+
- **Button Appearance:**
|
|
356
|
+
- When `state=true`: Orange color with eye-slash icon (items hidden)
|
|
357
|
+
- When `state=false`: Green color with eye icon (items shown)
|
|
358
|
+
- **Example:**
|
|
359
|
+
```jsx
|
|
360
|
+
const [hideCompleted, setHideCompleted] = useState(false);
|
|
361
|
+
const [hideArchived, setHideArchived] = useState(true);
|
|
362
|
+
|
|
363
|
+
filterActions={[
|
|
364
|
+
{
|
|
365
|
+
name: 'Completed',
|
|
366
|
+
state: hideCompleted,
|
|
367
|
+
function: () => setHideCompleted(!hideCompleted),
|
|
368
|
+
tooltip: 'Toggle completed items visibility',
|
|
369
|
+
key: 'filter-completed'
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: 'Archived',
|
|
373
|
+
state: hideArchived,
|
|
374
|
+
function: () => setHideArchived(!hideArchived),
|
|
375
|
+
tooltip: 'Toggle archived items visibility',
|
|
376
|
+
disabled: false,
|
|
377
|
+
visible: true
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
// Dynamic button text based on state
|
|
381
|
+
state: hideEvents,
|
|
382
|
+
name: hideEvents ? "Hiding Events" : "Showing Events",
|
|
383
|
+
tooltip: hideEvents ? "Show Events" : "Hide Events",
|
|
384
|
+
function: () => setHideEvents(!hideEvents),
|
|
385
|
+
visible: !!handleHideEvents, // Only show if handler exists
|
|
386
|
+
}
|
|
387
|
+
]}
|
|
388
|
+
```
|
|
389
|
+
|
|
343
390
|
#### `extraActions`
|
|
344
391
|
- **Type:** `Array<ExtraActionObject>`
|
|
345
392
|
- **Default:** `null`
|
|
@@ -1089,6 +1136,68 @@ function ProductGrid() {
|
|
|
1089
1136
|
}
|
|
1090
1137
|
```
|
|
1091
1138
|
|
|
1139
|
+
### Example 3.5: Grid with Filter Actions
|
|
1140
|
+
```jsx
|
|
1141
|
+
function TaskGrid() {
|
|
1142
|
+
const [tasks, setTasks] = useState(initialTasks);
|
|
1143
|
+
const [selected, setSelected] = useState([]);
|
|
1144
|
+
const [hideCompleted, setHideCompleted] = useState(false);
|
|
1145
|
+
const [hideArchived, setHideArchived] = useState(true);
|
|
1146
|
+
|
|
1147
|
+
// Filter data based on filter states
|
|
1148
|
+
const filteredTasks = useMemo(() => {
|
|
1149
|
+
return tasks.filter(task => {
|
|
1150
|
+
if (hideCompleted && task.status === 'completed') return false;
|
|
1151
|
+
if (hideArchived && task.isArchived) return false;
|
|
1152
|
+
return true;
|
|
1153
|
+
});
|
|
1154
|
+
}, [tasks, hideCompleted, hideArchived]);
|
|
1155
|
+
|
|
1156
|
+
const filterActions = [
|
|
1157
|
+
{
|
|
1158
|
+
name: 'Completed',
|
|
1159
|
+
state: hideCompleted,
|
|
1160
|
+
function: () => setHideCompleted(!hideCompleted),
|
|
1161
|
+
tooltip: hideCompleted ? 'Show completed tasks' : 'Hide completed tasks',
|
|
1162
|
+
key: 'filter-completed'
|
|
1163
|
+
},
|
|
1164
|
+
{
|
|
1165
|
+
name: 'Archived',
|
|
1166
|
+
state: hideArchived,
|
|
1167
|
+
function: () => setHideArchived(!hideArchived),
|
|
1168
|
+
tooltip: hideArchived ? 'Show archived tasks' : 'Hide archived tasks',
|
|
1169
|
+
key: 'filter-archived'
|
|
1170
|
+
},
|
|
1171
|
+
{
|
|
1172
|
+
// Example with dynamic name and conditional visibility
|
|
1173
|
+
state: hideUrgent,
|
|
1174
|
+
name: hideUrgent ? "Hiding Urgent" : "Showing Urgent",
|
|
1175
|
+
tooltip: hideUrgent ? "Show urgent tasks" : "Hide urgent tasks",
|
|
1176
|
+
function: () => setHideUrgent(!hideUrgent),
|
|
1177
|
+
visible: !!setHideUrgent, // Only show if handler exists
|
|
1178
|
+
}
|
|
1179
|
+
];
|
|
1180
|
+
|
|
1181
|
+
const columns = [
|
|
1182
|
+
{ accessorKey: 'id', header: 'ID', type: 'integer' },
|
|
1183
|
+
{ accessorKey: 'title', header: 'Task', type: 'textTitle' },
|
|
1184
|
+
{ accessorKey: 'status', header: 'Status', type: 'text' },
|
|
1185
|
+
{ accessorKey: 'dueDate', header: 'Due Date', type: 'date', isDateColumn: true },
|
|
1186
|
+
];
|
|
1187
|
+
|
|
1188
|
+
return (
|
|
1189
|
+
<DataGrid
|
|
1190
|
+
columns={columns}
|
|
1191
|
+
createRows={filteredTasks}
|
|
1192
|
+
rowKey="id"
|
|
1193
|
+
selectData={setSelected}
|
|
1194
|
+
filterActions={filterActions}
|
|
1195
|
+
gridHeight={600}
|
|
1196
|
+
/>
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
```
|
|
1200
|
+
|
|
1092
1201
|
### Example 4: Hierarchical Data with SubRows
|
|
1093
1202
|
|
|
1094
1203
|
```jsx
|
|
@@ -1519,8 +1628,26 @@ interface ActionObject {
|
|
|
1519
1628
|
}
|
|
1520
1629
|
```
|
|
1521
1630
|
|
|
1522
|
-
###
|
|
1631
|
+
### Filter Action Object
|
|
1632
|
+
```typescript
|
|
1633
|
+
interface FilterActionObject {
|
|
1634
|
+
// Required
|
|
1635
|
+
name: string; // Button label
|
|
1636
|
+
function: () => void; // Toggle handler
|
|
1637
|
+
state: boolean; // Current filter state (true=hidden, false=shown)
|
|
1638
|
+
|
|
1639
|
+
// Display
|
|
1640
|
+
tooltip?: string; // Hover tooltip
|
|
1641
|
+
icon?: string | React.Element; // Icon name or element (default: eye/eye-slash based on state)
|
|
1642
|
+
visible?: boolean; // Show/hide the button (default: true)
|
|
1643
|
+
|
|
1644
|
+
// Behavior
|
|
1645
|
+
disabled?: boolean; // Manually disable the button
|
|
1646
|
+
key?: string; // Unique React key (defaults to name)
|
|
1647
|
+
}
|
|
1648
|
+
```
|
|
1523
1649
|
|
|
1650
|
+
### Extra Action Object
|
|
1524
1651
|
```typescript
|
|
1525
1652
|
interface ExtraActionObject {
|
|
1526
1653
|
// Required
|
|
@@ -1532,6 +1659,7 @@ interface ExtraActionObject {
|
|
|
1532
1659
|
icon?: string | React.Element; // Icon name or element
|
|
1533
1660
|
style?: React.CSSProperties; // Custom button styles
|
|
1534
1661
|
propsButton?: object; // Additional Semantic UI Button props
|
|
1662
|
+
visible?: boolean; // Show/hide the button (default: true)
|
|
1535
1663
|
}
|
|
1536
1664
|
```
|
|
1537
1665
|
|
package/build/wrapper/index.js
CHANGED
|
@@ -44,6 +44,8 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
44
44
|
createRows = _ref.createRows,
|
|
45
45
|
_ref$actions = _ref.actions,
|
|
46
46
|
actions = _ref$actions === void 0 ? null : _ref$actions,
|
|
47
|
+
_ref$filerActions = _ref.filerActions,
|
|
48
|
+
filerActions = _ref$filerActions === void 0 ? null : _ref$filerActions,
|
|
47
49
|
_ref$extraActions = _ref.extraActions,
|
|
48
50
|
extraActions = _ref$extraActions === void 0 ? null : _ref$extraActions,
|
|
49
51
|
_ref$hasExcelExport = _ref.hasExcelExport,
|
|
@@ -253,6 +255,12 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
253
255
|
var renderTopToolbarCustomActions = function renderTopToolbarCustomActions(_ref2) {
|
|
254
256
|
var table = _ref2.table;
|
|
255
257
|
var selectedRows = table.getSelectedRowModel().flatRows;
|
|
258
|
+
var defaultStyle = {
|
|
259
|
+
display: 'flex',
|
|
260
|
+
height: '36px',
|
|
261
|
+
alignItems: 'center',
|
|
262
|
+
justifyContent: 'center'
|
|
263
|
+
};
|
|
256
264
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
257
265
|
style: {
|
|
258
266
|
display: 'flex',
|
|
@@ -272,7 +280,9 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
272
280
|
gap: '.5em',
|
|
273
281
|
flexWrap: 'wrap'
|
|
274
282
|
},
|
|
275
|
-
children: (actions === null || actions === void 0 ? void 0 : actions.length) > 0 && actions.
|
|
283
|
+
children: (actions === null || actions === void 0 ? void 0 : actions.length) > 0 && actions.filter(function (e) {
|
|
284
|
+
return e.visible !== undefined ? e.visible : true;
|
|
285
|
+
}).map(function (e) {
|
|
276
286
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ActionButton["default"], {
|
|
277
287
|
table: table,
|
|
278
288
|
toggle: e.toggle,
|
|
@@ -297,7 +307,9 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
297
307
|
flexWrap: 'wrap',
|
|
298
308
|
gap: 3
|
|
299
309
|
},
|
|
300
|
-
children: [(extraActions === null || extraActions === void 0 ? void 0 : extraActions.length) > 0 && extraActions.
|
|
310
|
+
children: [(extraActions === null || extraActions === void 0 ? void 0 : extraActions.length) > 0 && extraActions.filter(function (e) {
|
|
311
|
+
return e.visible !== undefined ? e.visible : true;
|
|
312
|
+
}).map(function (a, idx) {
|
|
301
313
|
var _ref3 = a || {},
|
|
302
314
|
fnc = _ref3["function"],
|
|
303
315
|
content = _ref3.content,
|
|
@@ -307,12 +319,6 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
307
319
|
_ref3$style = _ref3.style,
|
|
308
320
|
style = _ref3$style === void 0 ? {} : _ref3$style,
|
|
309
321
|
propsButton = _ref3.propsButton;
|
|
310
|
-
var defaultStyle = {
|
|
311
|
-
display: 'flex',
|
|
312
|
-
height: '36px',
|
|
313
|
-
alignItems: 'center',
|
|
314
|
-
justifyContent: 'center'
|
|
315
|
-
};
|
|
316
322
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
317
323
|
title: tooltip || content,
|
|
318
324
|
arrow: true,
|
|
@@ -328,6 +334,41 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
328
334
|
}, propsButton))
|
|
329
335
|
})
|
|
330
336
|
}, "extraActions" + idx);
|
|
337
|
+
}), (filerActions === null || filerActions === void 0 ? void 0 : filerActions.length) > 0 && filerActions.filter(function (e) {
|
|
338
|
+
return e.visible !== undefined ? e.visible : true;
|
|
339
|
+
}).map(function (e, idx) {
|
|
340
|
+
var _ref4 = e || {},
|
|
341
|
+
state = _ref4.state,
|
|
342
|
+
fnc = _ref4["function"],
|
|
343
|
+
key = _ref4.key,
|
|
344
|
+
name = _ref4.name,
|
|
345
|
+
_ref4$tooltip = _ref4.tooltip,
|
|
346
|
+
tooltip = _ref4$tooltip === void 0 ? '' : _ref4$tooltip,
|
|
347
|
+
disabled = _ref4.disabled;
|
|
348
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
349
|
+
title: tooltip || name,
|
|
350
|
+
arrow: true,
|
|
351
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
352
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_semanticUiReact.Button, _objectSpread(_objectSpread({
|
|
353
|
+
circular: true,
|
|
354
|
+
toggle: true,
|
|
355
|
+
active: !state,
|
|
356
|
+
inverted: true,
|
|
357
|
+
color: state ? "orange" : "green"
|
|
358
|
+
}, name ? {
|
|
359
|
+
content: name
|
|
360
|
+
} : {}), {}, {
|
|
361
|
+
onClick: fnc,
|
|
362
|
+
icon: state ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_semanticUiReact.Icon, {
|
|
363
|
+
name: "eye slash"
|
|
364
|
+
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_semanticUiReact.Icon, {
|
|
365
|
+
name: "eye"
|
|
366
|
+
}),
|
|
367
|
+
disabled: disabled,
|
|
368
|
+
style: defaultStyle
|
|
369
|
+
}), key || name)
|
|
370
|
+
})
|
|
371
|
+
}, "filterActions" + idx);
|
|
331
372
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ExportActions["default"], {
|
|
332
373
|
table: table,
|
|
333
374
|
data: createRows,
|
|
@@ -353,12 +394,7 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
353
394
|
}),
|
|
354
395
|
primary: true,
|
|
355
396
|
inverted: true,
|
|
356
|
-
style:
|
|
357
|
-
display: 'flex',
|
|
358
|
-
height: '36px',
|
|
359
|
-
alignItems: 'center',
|
|
360
|
-
justifyContent: 'center'
|
|
361
|
-
}
|
|
397
|
+
style: defaultStyle
|
|
362
398
|
})
|
|
363
399
|
})
|
|
364
400
|
}), hasClearSelectionBtn && (!disableSelect || disableRows.length > 0) && /*#__PURE__*/(0, _jsxRuntime.jsx)(_material.Tooltip, {
|
|
@@ -518,16 +554,16 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
518
554
|
filterRegex: 'Regex',
|
|
519
555
|
filterLogical: 'Logical'
|
|
520
556
|
},
|
|
521
|
-
renderColumnFilterModeMenuItems: function renderColumnFilterModeMenuItems(
|
|
522
|
-
var internalFilterOptions =
|
|
523
|
-
onSelectFilterMode =
|
|
557
|
+
renderColumnFilterModeMenuItems: function renderColumnFilterModeMenuItems(_ref5) {
|
|
558
|
+
var internalFilterOptions = _ref5.internalFilterOptions,
|
|
559
|
+
onSelectFilterMode = _ref5.onSelectFilterMode;
|
|
524
560
|
return [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ColumnFilter["default"], {
|
|
525
561
|
filterOptions: internalFilterOptions,
|
|
526
562
|
onSelectFilterMode: onSelectFilterMode
|
|
527
563
|
}, "filters")];
|
|
528
564
|
},
|
|
529
|
-
renderTopToolbar: function renderTopToolbar(
|
|
530
|
-
var table =
|
|
565
|
+
renderTopToolbar: function renderTopToolbar(_ref6) {
|
|
566
|
+
var table = _ref6.table;
|
|
531
567
|
var selectedRows = table.getSelectedRowModel().flatRows;
|
|
532
568
|
var _table$getState$pagin = table.getState().pagination,
|
|
533
569
|
pageIndex = _table$getState$pagin.pageIndex,
|
|
@@ -654,8 +690,8 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
654
690
|
padding: 'auto'
|
|
655
691
|
})
|
|
656
692
|
},
|
|
657
|
-
muiTableBodyCellProps: function muiTableBodyCellProps(
|
|
658
|
-
var row =
|
|
693
|
+
muiTableBodyCellProps: function muiTableBodyCellProps(_ref7) {
|
|
694
|
+
var row = _ref7.row;
|
|
659
695
|
var isDisabled = disableRows.length > 0 ? disableRows.includes(row.original[rowKey]) : false;
|
|
660
696
|
return {
|
|
661
697
|
sx: _objectSpread(_objectSpread({
|
|
@@ -750,8 +786,8 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
750
786
|
};
|
|
751
787
|
},
|
|
752
788
|
onRowSelectionChange: setRowSelection,
|
|
753
|
-
muiTableBodyRowProps: function muiTableBodyRowProps(
|
|
754
|
-
var row =
|
|
789
|
+
muiTableBodyRowProps: function muiTableBodyRowProps(_ref8) {
|
|
790
|
+
var row = _ref8.row;
|
|
755
791
|
return {
|
|
756
792
|
sx: {
|
|
757
793
|
backgroundColor: row.depth > 0 ? '#f0f0f0' : 'white'
|
|
@@ -763,8 +799,8 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
763
799
|
enableTopToolbar: enableTopToolbar,
|
|
764
800
|
enableBottomToolbar: enableBottomToolbar,
|
|
765
801
|
enableExpanding: enableExpanding,
|
|
766
|
-
muiSelectCheckboxProps: function muiSelectCheckboxProps(
|
|
767
|
-
var row =
|
|
802
|
+
muiSelectCheckboxProps: function muiSelectCheckboxProps(_ref9) {
|
|
803
|
+
var row = _ref9.row;
|
|
768
804
|
return {
|
|
769
805
|
checked: rowSelection[row.id] || false,
|
|
770
806
|
onChange: function onChange() {
|
|
@@ -815,7 +851,7 @@ var DataGrid = function DataGrid(_ref) {
|
|
|
815
851
|
return r.original;
|
|
816
852
|
});
|
|
817
853
|
if (onVisibleRowsChange) onVisibleRowsChange(rows);
|
|
818
|
-
}, [table, onVisibleRowsChange]);
|
|
854
|
+
}, [table.getRowModel().rows, onVisibleRowsChange]);
|
|
819
855
|
(0, _react.useEffect)(function () {
|
|
820
856
|
if (enableFixedHeader) (0, _gridFixedHeader["default"])('fixed-header', enableFixedActions);
|
|
821
857
|
}, [enableFixedHeader, enableFixedActions]);
|
|
@@ -853,16 +889,26 @@ DataGrid.propTypes = {
|
|
|
853
889
|
icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].string]),
|
|
854
890
|
selectionMode: _propTypes["default"].oneOf(['single', 'multi', 'always']),
|
|
855
891
|
confirmMessage: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].string]),
|
|
856
|
-
hasConfirmMessage: _propTypes["default"].bool
|
|
892
|
+
hasConfirmMessage: _propTypes["default"].bool,
|
|
893
|
+
visible: _propTypes["default"].bool
|
|
857
894
|
})),
|
|
858
895
|
// array of objects -> each object represents a single data grid action button
|
|
896
|
+
filerActions: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
897
|
+
name: _propTypes["default"].string,
|
|
898
|
+
"function": _propTypes["default"].func.isRequired,
|
|
899
|
+
tooltip: _propTypes["default"].string,
|
|
900
|
+
icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].string]),
|
|
901
|
+
visible: _propTypes["default"].bool
|
|
902
|
+
})),
|
|
903
|
+
// array of objects -> each object represents a single data grid filter action button
|
|
859
904
|
extraActions: _propTypes["default"].arrayOf(_propTypes["default"].shape({
|
|
860
905
|
tooltip: _propTypes["default"].string,
|
|
861
906
|
"function": _propTypes["default"].func.isRequired,
|
|
862
907
|
content: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].element]).isRequired,
|
|
863
908
|
icon: _propTypes["default"].oneOfType([_propTypes["default"].element, _propTypes["default"].string]),
|
|
864
909
|
style: _propTypes["default"].object,
|
|
865
|
-
propsButton: _propTypes["default"].object
|
|
910
|
+
propsButton: _propTypes["default"].object,
|
|
911
|
+
visible: _propTypes["default"].bool
|
|
866
912
|
})),
|
|
867
913
|
// array of objects -> each object represents a single data grid extra action button
|
|
868
914
|
hasExcelExport: _propTypes["default"].bool,
|