@insticc/react-datagrid-2 1.1.28 → 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.
Files changed (2) hide show
  1. package/README.md +129 -1
  2. 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
- ### Extra Action Object
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insticc/react-datagrid-2",
3
- "version": "1.1.28",
3
+ "version": "1.1.29",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "files": [