@kareemelbalshe/any-table 1.2.0 → 1.4.0
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/CHANGELOG.md +46 -0
- package/README.md +178 -0
- package/dist/adapters/columnFilterAdapter.d.ts +9 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/columns/pinningUtils.d.ts +1 -0
- package/dist/components/TableBody.d.ts +7 -1
- package/dist/components/TableBulkBar.d.ts +13 -0
- package/dist/components/TableFooter.d.ts +15 -0
- package/dist/components/TableHeader.d.ts +7 -2
- package/dist/components/TableToolbar.d.ts +19 -3
- package/dist/components/index.d.ts +3 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/useAnyTable.d.ts +42 -3
- package/dist/hooks/useAnyTableColumnFilters.d.ts +19 -0
- package/dist/hooks/useAnyTableColumnVisibility.d.ts +17 -0
- package/dist/hooks/useAnyTableController.d.ts +12 -3
- package/dist/hooks/useAnyTableData.d.ts +3 -1
- package/dist/hooks/useAnyTableExpand.d.ts +15 -0
- package/dist/i18n/messages.d.ts +24 -0
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3094 -1736
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/dist/types/api.types.d.ts +2 -0
- package/dist/types/column.types.d.ts +58 -0
- package/dist/types/table.types.d.ts +151 -4
- package/package.json +9 -2
|
@@ -1,14 +1,55 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { ColumnDef, SortDirection } from './column.types';
|
|
3
3
|
import { TableAction, SwitchAction } from './action.types';
|
|
4
|
-
import { ApiConfig } from './api.types';
|
|
4
|
+
import { ApiConfig, ApiFetcherParams } from './api.types';
|
|
5
5
|
import { AnyTableTheme, TablePreset } from './theme.types';
|
|
6
6
|
import { TableMessages } from '../i18n';
|
|
7
|
-
export
|
|
7
|
+
export type ExportScope = "all" | "current-page" | "selected" | "auto";
|
|
8
|
+
export interface ExportContext<TData = any> {
|
|
9
|
+
format: "csv" | "json";
|
|
10
|
+
scope: ExportScope;
|
|
11
|
+
search: string;
|
|
12
|
+
sortBy: string | null;
|
|
13
|
+
sortOrder: SortDirection;
|
|
14
|
+
filters?: Record<string, any>;
|
|
15
|
+
params?: Record<string, any>;
|
|
16
|
+
currentPageRows: TData[];
|
|
17
|
+
selectedRows: TData[];
|
|
18
|
+
selectedKeys: (string | number)[];
|
|
19
|
+
totalRecords: number;
|
|
20
|
+
columns: ColumnDef<TData>[];
|
|
21
|
+
defaultExport: (rows: TData[], filename?: string) => void;
|
|
22
|
+
}
|
|
23
|
+
export interface ExportConfig<TData = any> {
|
|
8
24
|
enabled?: boolean;
|
|
9
25
|
csv?: boolean;
|
|
10
26
|
json?: boolean;
|
|
11
27
|
filename?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Default export scope:
|
|
30
|
+
* - 'all': Exports all filtered rows (all matching client records, or calls fetchAllRows in server mode).
|
|
31
|
+
* - 'current-page': Exports only the current page of visible rows.
|
|
32
|
+
* - 'selected': Exports currently selected rows (falls back to all filtered if none selected).
|
|
33
|
+
* - 'auto': In client mode exports 'all'; in server mode exports 'all' if fetchAllRows/onExport is provided, otherwise 'current-page'.
|
|
34
|
+
* Defaults to 'auto'.
|
|
35
|
+
*/
|
|
36
|
+
scope?: ExportScope;
|
|
37
|
+
/**
|
|
38
|
+
* For server-side pagination:
|
|
39
|
+
* A function that fetches all matching filtered rows from the backend,
|
|
40
|
+
* OR `true` to automatically invoke `api.fetcher` with all current search/sort/filter parameters without pagination limit (e.g. limit: totalRecords or all: true).
|
|
41
|
+
* AnyTable takes care of generating the CSV/JSON with RTL & Excel BOM, column mapping, and triggering the file download.
|
|
42
|
+
*/
|
|
43
|
+
fetchAllRows?: boolean | ((params: ApiFetcherParams) => Promise<TData[]> | TData[]);
|
|
44
|
+
/**
|
|
45
|
+
* Custom export handler for full control over export logic (e.g. triggering server-side CSV streaming, backend download URLs, or reporting).
|
|
46
|
+
*/
|
|
47
|
+
onExport?: (format: "csv" | "json", context: ExportContext<TData>) => Promise<void> | void;
|
|
48
|
+
/**
|
|
49
|
+
* Whether to show multiple scope options in the export dropdown (e.g. All Filtered vs Current Page vs Selected).
|
|
50
|
+
* Defaults to false.
|
|
51
|
+
*/
|
|
52
|
+
showScopeOptions?: boolean;
|
|
12
53
|
}
|
|
13
54
|
export type RowKeyResolver<TData = any> = (keyof TData & string) | string | ((row: TData, index: number) => string | number);
|
|
14
55
|
export interface SearchConfig<TData = any> {
|
|
@@ -58,6 +99,47 @@ export interface VirtualizedConfig {
|
|
|
58
99
|
*/
|
|
59
100
|
overscan?: number;
|
|
60
101
|
}
|
|
102
|
+
export interface ColumnVisibilityConfig {
|
|
103
|
+
enabled?: boolean;
|
|
104
|
+
storageKey?: string;
|
|
105
|
+
defaultHiddenColumns?: string[];
|
|
106
|
+
onVisibilityChange?: (hiddenColumns: string[], visibleColumns: string[]) => void;
|
|
107
|
+
allowReset?: boolean;
|
|
108
|
+
}
|
|
109
|
+
export interface ColumnFiltersConfig {
|
|
110
|
+
enabled?: boolean;
|
|
111
|
+
mode?: "client" | "server" | "auto";
|
|
112
|
+
defaultFilters?: Record<string, any>;
|
|
113
|
+
defaultOpen?: boolean;
|
|
114
|
+
onFilterChange?: (filters: Record<string, any>) => void;
|
|
115
|
+
showClearAll?: boolean;
|
|
116
|
+
}
|
|
117
|
+
export interface ExpandableConfig<TData = any> {
|
|
118
|
+
render: (row: TData, index: number) => React.ReactNode;
|
|
119
|
+
rowExpandable?: (row: TData, index: number) => boolean;
|
|
120
|
+
defaultExpandedKeys?: (string | number)[];
|
|
121
|
+
expandRowByClick?: boolean;
|
|
122
|
+
accordion?: boolean;
|
|
123
|
+
onExpandChange?: (expandedKeys: (string | number)[]) => void;
|
|
124
|
+
}
|
|
125
|
+
export interface CellEditParams<TData = any> {
|
|
126
|
+
row: TData;
|
|
127
|
+
rowKey: string | number;
|
|
128
|
+
columnKey: string;
|
|
129
|
+
oldValue: any;
|
|
130
|
+
newValue: any;
|
|
131
|
+
rowIndex: number;
|
|
132
|
+
}
|
|
133
|
+
export interface BulkAction<TData = any> {
|
|
134
|
+
id: string;
|
|
135
|
+
label: string;
|
|
136
|
+
icon?: React.ReactNode;
|
|
137
|
+
variant?: "primary" | "danger" | "warning" | "success" | "neutral";
|
|
138
|
+
onClick: (selectedRows: TData[], selectedKeys: (string | number)[], context: {
|
|
139
|
+
clearSelection: () => void;
|
|
140
|
+
refresh: () => Promise<void>;
|
|
141
|
+
}) => Promise<void> | void;
|
|
142
|
+
}
|
|
61
143
|
export interface TableState<TData = any> {
|
|
62
144
|
data: TData[];
|
|
63
145
|
loading: boolean;
|
|
@@ -69,9 +151,13 @@ export interface TableState<TData = any> {
|
|
|
69
151
|
search: string;
|
|
70
152
|
sortBy: string | null;
|
|
71
153
|
sortOrder: SortDirection;
|
|
154
|
+
filters?: Record<string, any>;
|
|
155
|
+
hiddenColumns?: string[];
|
|
156
|
+
expandedRowKeys?: (string | number)[];
|
|
72
157
|
selectedRowKeys: (string | number)[];
|
|
73
158
|
selectedRows: TData[];
|
|
74
159
|
isServerMode: boolean;
|
|
160
|
+
isExporting?: boolean;
|
|
75
161
|
}
|
|
76
162
|
export interface TableInstance<TData = any> {
|
|
77
163
|
/**
|
|
@@ -129,7 +215,43 @@ export interface TableInstance<TData = any> {
|
|
|
129
215
|
/**
|
|
130
216
|
* Triggers file download of the current table data (CSV or JSON).
|
|
131
217
|
*/
|
|
132
|
-
exportData?: (format?: "csv" | "json", filename?: string) => void
|
|
218
|
+
exportData?: (format?: "csv" | "json", filename?: string, scope?: ExportScope) => Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Whether an export operation is currently fetching data or generating a file.
|
|
221
|
+
*/
|
|
222
|
+
isExporting?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Programmatically sets a single column filter value.
|
|
225
|
+
*/
|
|
226
|
+
setColumnFilter?: (key: string, value: any) => void;
|
|
227
|
+
/**
|
|
228
|
+
* Clears all active per-column filters.
|
|
229
|
+
*/
|
|
230
|
+
clearColumnFilters?: () => void;
|
|
231
|
+
/**
|
|
232
|
+
* Toggles visibility of a column by its key.
|
|
233
|
+
*/
|
|
234
|
+
toggleColumnVisibility?: (key: string) => void;
|
|
235
|
+
/**
|
|
236
|
+
* Sets the list of hidden column keys directly.
|
|
237
|
+
*/
|
|
238
|
+
setHiddenColumns?: (keys: string[]) => void;
|
|
239
|
+
/**
|
|
240
|
+
* Resets column visibility to initial defaults and clears persisted storage.
|
|
241
|
+
*/
|
|
242
|
+
resetColumnVisibility?: () => void;
|
|
243
|
+
/**
|
|
244
|
+
* Toggles expansion state of a row by its key.
|
|
245
|
+
*/
|
|
246
|
+
toggleExpandRow?: (key: string | number) => void;
|
|
247
|
+
/**
|
|
248
|
+
* Expands all currently loaded rows.
|
|
249
|
+
*/
|
|
250
|
+
expandAllRows?: () => void;
|
|
251
|
+
/**
|
|
252
|
+
* Collapses all expanded rows.
|
|
253
|
+
*/
|
|
254
|
+
collapseAllRows?: () => void;
|
|
133
255
|
}
|
|
134
256
|
export interface AnyTableProps<TData = any> {
|
|
135
257
|
/**
|
|
@@ -295,11 +417,36 @@ export interface AnyTableProps<TData = any> {
|
|
|
295
417
|
/**
|
|
296
418
|
* Built-in CSV & JSON export engine configuration or boolean to enable export in toolbar.
|
|
297
419
|
*/
|
|
298
|
-
exportable?: boolean | ExportConfig
|
|
420
|
+
exportable?: boolean | ExportConfig<TData>;
|
|
299
421
|
/**
|
|
300
422
|
* Enables interactive column width resizing handles on the table header. Defaults to false.
|
|
301
423
|
*/
|
|
302
424
|
resizableColumns?: boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Enables column visibility toggle menu in the toolbar with optional localStorage persistence.
|
|
427
|
+
*/
|
|
428
|
+
columnVisibility?: boolean | ColumnVisibilityConfig;
|
|
429
|
+
/**
|
|
430
|
+
* Enables smart per-column filter inputs/dropdowns below the header row.
|
|
431
|
+
*/
|
|
432
|
+
columnFilters?: boolean | ColumnFiltersConfig;
|
|
433
|
+
/**
|
|
434
|
+
* Enables expandable Master-Detail rows with custom detail panel rendering.
|
|
435
|
+
*/
|
|
436
|
+
expandable?: ExpandableConfig<TData>;
|
|
437
|
+
/**
|
|
438
|
+
* Callback invoked when an editable cell value is committed (double-click or Enter).
|
|
439
|
+
* Return `false` or reject to cancel the edit.
|
|
440
|
+
*/
|
|
441
|
+
onCellEdit?: (params: CellEditParams<TData>) => Promise<void | boolean> | void | boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Contextual bulk action buttons rendered when rows are selected (`selectable=true`).
|
|
444
|
+
*/
|
|
445
|
+
bulkActions?: BulkAction<TData>[];
|
|
446
|
+
/**
|
|
447
|
+
* Controls whether the summary/aggregation footer row renders when columns define `summary`. Defaults to true.
|
|
448
|
+
*/
|
|
449
|
+
showSummary?: boolean;
|
|
303
450
|
thead?: string[];
|
|
304
451
|
headerData?: string[];
|
|
305
452
|
tbodys?: TData[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kareemelbalshe/any-table",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Zero-config, zero-dependency smart data table for React (16.8+ to 19+) with 100k+ DOM virtualization, 3-tier REST API auto-detection,
|
|
3
|
+
"version": "1.4.0",
|
|
4
|
+
"description": "Zero-config, zero-dependency smart data table for React (16.8+ to 19+) with 100k+ DOM virtualization, 3-tier REST API auto-detection, per-column filters, column visibility persistence, expandable rows, inline cell editing, bulk actions, summary footer, CSV/Excel export, and first-class RTL & Arabic.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
7
7
|
"table",
|
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
"pagination",
|
|
13
13
|
"sorting",
|
|
14
14
|
"search",
|
|
15
|
+
"column-filters",
|
|
16
|
+
"column-visibility",
|
|
17
|
+
"expandable-rows",
|
|
18
|
+
"master-detail",
|
|
19
|
+
"inline-editing",
|
|
20
|
+
"bulk-actions",
|
|
21
|
+
"table-aggregation",
|
|
15
22
|
"auto-columns",
|
|
16
23
|
"typescript",
|
|
17
24
|
"react-table",
|