react-kd-grid 5.0.1
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 +309 -0
- package/dist/components/CellEditor.d.ts +23 -0
- package/dist/components/ColumnFilterSelector.d.ts +18 -0
- package/dist/components/CustomSelect.d.ts +14 -0
- package/dist/components/FooterAggregate.d.ts +16 -0
- package/dist/components/GridHeader.d.ts +39 -0
- package/dist/components/GridRows.d.ts +53 -0
- package/dist/components/GroupBar.d.ts +12 -0
- package/dist/components/GroupHeader.d.ts +29 -0
- package/dist/components/LicenseError.d.ts +9 -0
- package/dist/components/NoDataMessage.d.ts +11 -0
- package/dist/components/PaginationControls.d.ts +18 -0
- package/dist/components/Popover.d.ts +17 -0
- package/dist/components/RowContextMenu.d.ts +18 -0
- package/dist/components/SearchToolbar.d.ts +66 -0
- package/dist/components/filters/BooleanFilter.d.ts +7 -0
- package/dist/components/filters/DateFilter.d.ts +9 -0
- package/dist/components/filters/FilterContent.d.ts +9 -0
- package/dist/components/filters/FilterPopup.d.ts +2 -0
- package/dist/components/filters/MultiselectFilter.d.ts +10 -0
- package/dist/components/filters/NumberFilter.d.ts +9 -0
- package/dist/components/filters/TextFilter.d.ts +8 -0
- package/dist/components/filters/index.d.ts +6 -0
- package/dist/components/ui/DatePicker.d.ts +10 -0
- package/dist/constants.d.ts +1 -0
- package/dist/core/DataGrid.d.ts +3 -0
- package/dist/hooks/useAdvancedFiltering.d.ts +18 -0
- package/dist/hooks/useCellSelection.d.ts +67 -0
- package/dist/hooks/useColumnState.d.ts +45 -0
- package/dist/hooks/useDataWorker.d.ts +11 -0
- package/dist/hooks/useEditingCell.d.ts +49 -0
- package/dist/hooks/useExport.d.ts +14 -0
- package/dist/hooks/useGrouping.d.ts +28 -0
- package/dist/hooks/useInfiniteScroll.d.ts +31 -0
- package/dist/hooks/useLoadingBar.d.ts +21 -0
- package/dist/hooks/usePagination.d.ts +28 -0
- package/dist/hooks/useScrollSync.d.ts +29 -0
- package/dist/hooks/useSelection.d.ts +13 -0
- package/dist/hooks/useVirtualization.d.ts +17 -0
- package/dist/icons/index.d.ts +54 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.esm.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +592 -0
- package/dist/utils/dateUtils.d.ts +16 -0
- package/dist/utils/highlightText.d.ts +15 -0
- package/dist/utils/license.d.ts +3 -0
- package/package.json +97 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import { CSSProperties, MouseEvent, ReactNode } from "react";
|
|
2
|
+
/** Used internally by useVirtualization and GridRows. Not part of the public API. */
|
|
3
|
+
export interface VirtualizedRange {
|
|
4
|
+
startIndex: number;
|
|
5
|
+
endIndex: number;
|
|
6
|
+
offsetY: number;
|
|
7
|
+
}
|
|
8
|
+
export type FilterType = "text" | "multiselect" | "number" | "date" | "boolean";
|
|
9
|
+
export type Density = "sm" | "md" | "lg";
|
|
10
|
+
export type SortDirection = "asc" | "desc" | null;
|
|
11
|
+
export type PaginationMode = "client" | "server";
|
|
12
|
+
export type SearchMode = "contains" | "exact" | "startsWith" | "endsWith" | "regex";
|
|
13
|
+
export interface FilterOption {
|
|
14
|
+
label: string;
|
|
15
|
+
/** Tightened from `any` — filter values must be scalar. */
|
|
16
|
+
value: string | number | boolean;
|
|
17
|
+
}
|
|
18
|
+
/** Inline column filter configuration (used as `filterable: { type, ... }`). */
|
|
19
|
+
export interface ColumnFilter {
|
|
20
|
+
type: FilterType;
|
|
21
|
+
options?: FilterOption[];
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
min?: number;
|
|
24
|
+
max?: number;
|
|
25
|
+
}
|
|
26
|
+
export interface ColumnFilterValue {
|
|
27
|
+
type: FilterType;
|
|
28
|
+
/**
|
|
29
|
+
* The filter value.
|
|
30
|
+
* - Text/boolean: `string | boolean`
|
|
31
|
+
* - Number: `number | string`
|
|
32
|
+
* - Date: `Date | string`
|
|
33
|
+
* - Multiselect: `any[]` (array of selected option values)
|
|
34
|
+
*/
|
|
35
|
+
value: string | number | boolean | Date | Array<string | number | boolean> | null;
|
|
36
|
+
operator?: "equals" | "contains" | "startsWith" | "endsWith" | "gt" | "lt" | "gte" | "lte" | "between";
|
|
37
|
+
/** Secondary value for the `between` operator. */
|
|
38
|
+
secondValue?: string | number | boolean | Date | null;
|
|
39
|
+
}
|
|
40
|
+
export interface ActiveFilters {
|
|
41
|
+
[columnKey: string]: ColumnFilterValue | null;
|
|
42
|
+
}
|
|
43
|
+
/** @internal Used by FilterPopup component. */
|
|
44
|
+
export interface FilterPopupProps {
|
|
45
|
+
column: GridColumn;
|
|
46
|
+
data: GridRow[];
|
|
47
|
+
currentFilter?: ColumnFilterValue;
|
|
48
|
+
onApplyFilter: (filter: ColumnFilterValue | null) => void;
|
|
49
|
+
onClose: () => void;
|
|
50
|
+
position: {
|
|
51
|
+
top: number;
|
|
52
|
+
left: number;
|
|
53
|
+
};
|
|
54
|
+
autoApply?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export interface GridColumn {
|
|
57
|
+
key: string;
|
|
58
|
+
header: string;
|
|
59
|
+
width?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Flexible sizing. When `true` or a positive number the column can expand to
|
|
62
|
+
* fill available horizontal space. A number sets the flex-grow weight.
|
|
63
|
+
*/
|
|
64
|
+
flex?: boolean | number;
|
|
65
|
+
/** Minimum width in pixels. */
|
|
66
|
+
minWidth?: number;
|
|
67
|
+
/** Maximum width in pixels. */
|
|
68
|
+
maxWidth?: number;
|
|
69
|
+
/** Allow the user to drag-resize this column. */
|
|
70
|
+
resizable?: boolean;
|
|
71
|
+
/** Whether the column header is clickable to sort. Default `true`. */
|
|
72
|
+
sortable?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Enable or configure the column filter.
|
|
75
|
+
* `true` → text filter with defaults
|
|
76
|
+
* `false` → no filter (overrides the grid-level `filterable` prop)
|
|
77
|
+
* object → full configuration
|
|
78
|
+
*/
|
|
79
|
+
filterable?: boolean | ColumnFilter;
|
|
80
|
+
/** Format the raw cell value to a display string. */
|
|
81
|
+
formatter?: (value: any) => string;
|
|
82
|
+
/** Fully custom cell renderer; takes precedence over `formatter`. */
|
|
83
|
+
cellRenderer?: (value: any, row: GridRow) => ReactNode;
|
|
84
|
+
/** Whether the column is visible. Default `true`. */
|
|
85
|
+
visible?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Aggregate function applied to this column's values inside group footers.
|
|
88
|
+
* Built-ins: `"sum" | "avg" | "min" | "max"`.
|
|
89
|
+
* Custom: `(values: any[]) => any`.
|
|
90
|
+
*/
|
|
91
|
+
aggregate?: "sum" | "avg" | "min" | "max" | ((values: any[]) => any);
|
|
92
|
+
/** Formatter for the group-footer aggregate value. Falls back to `formatter`. */
|
|
93
|
+
aggregateFormatter?: (value: any) => string;
|
|
94
|
+
/**
|
|
95
|
+
* Aggregate function for the global footer row at the bottom of all rows.
|
|
96
|
+
* Built-ins: `"count" | "sum" | "avg" | "min" | "max"`.
|
|
97
|
+
*
|
|
98
|
+
* @renamed Was `footer_aggregate` (snake_case) in v2. Now `footerAggregate`.
|
|
99
|
+
*/
|
|
100
|
+
footerAggregate?: "count" | "sum" | "avg" | "min" | "max" | ((values: any[]) => any);
|
|
101
|
+
/** Formatter for the global footer aggregate value. Falls back to `formatter`. */
|
|
102
|
+
footerAggregateFormatter?: (value: any) => string;
|
|
103
|
+
/** Horizontal alignment for cell content. */
|
|
104
|
+
align?: "left" | "center" | "right";
|
|
105
|
+
/** Horizontal alignment for the header cell. */
|
|
106
|
+
headerAlign?: "left" | "center" | "right";
|
|
107
|
+
/** CSS class for body cells — static string or derived from value + row. */
|
|
108
|
+
className?: string | ((value: any, row: GridRow) => string);
|
|
109
|
+
/** Inline style for body cells — static or derived. */
|
|
110
|
+
cellStyle?: CSSProperties | ((value: any, row: GridRow) => CSSProperties);
|
|
111
|
+
/** CSS class for the header cell. */
|
|
112
|
+
headerClassName?: string;
|
|
113
|
+
/** Remove default padding from the cell container. */
|
|
114
|
+
noPadding?: boolean;
|
|
115
|
+
/** Set to `false` to opt out of the default truncation wrapper. */
|
|
116
|
+
wrapCellContent?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Tooltip shown on hover of body cells.
|
|
119
|
+
* - `string` — static tooltip text
|
|
120
|
+
* - Function — derived from the cell value and its row
|
|
121
|
+
*
|
|
122
|
+
* When omitted, the grid falls back to the native browser `title` attribute
|
|
123
|
+
* (which shows the `displayValue` of the cell).
|
|
124
|
+
*/
|
|
125
|
+
tooltip?: string | ((value: any, row: GridRow) => string);
|
|
126
|
+
/**
|
|
127
|
+
* Tooltip shown on hover of the column header cell.
|
|
128
|
+
* Useful for describing long or abbreviated column names.
|
|
129
|
+
*/
|
|
130
|
+
headerTooltip?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Enable inline cell editing for this column.
|
|
133
|
+
* - `true` → all rows editable
|
|
134
|
+
* - Function → called per-row; return `false` to make that row read-only.
|
|
135
|
+
*/
|
|
136
|
+
editable?: boolean | ((row: GridRow) => boolean);
|
|
137
|
+
/**
|
|
138
|
+
* Input type to use for the built-in editor.
|
|
139
|
+
* - `"text"` (default) → `<input type="text">`
|
|
140
|
+
* - `"number"` → `<input type="number">`
|
|
141
|
+
* - `"date"` → `<input type="date">`
|
|
142
|
+
* - `"select"` → `<select>` (requires `editorOptions`)
|
|
143
|
+
* - `"textarea"` → `<textarea>` (expands the row)
|
|
144
|
+
*/
|
|
145
|
+
editorType?: "text" | "number" | "date" | "select" | "textarea";
|
|
146
|
+
/** Options for the built-in `"select"` editor. */
|
|
147
|
+
editorOptions?: Array<{
|
|
148
|
+
label: string;
|
|
149
|
+
value: any;
|
|
150
|
+
}>;
|
|
151
|
+
/**
|
|
152
|
+
* Fully custom editor renderer. When provided it replaces the built-in
|
|
153
|
+
* input. Receives the current draft value, the full row, and callbacks
|
|
154
|
+
* to commit or cancel the edit.
|
|
155
|
+
*/
|
|
156
|
+
editor?: (value: any, row: GridRow, onCommit: (newValue: any) => void, onCancel: () => void) => ReactNode;
|
|
157
|
+
}
|
|
158
|
+
export interface GridRow {
|
|
159
|
+
/** Optional unique identifier. Provide `getRowId` on the grid for custom keys. */
|
|
160
|
+
id?: string | number;
|
|
161
|
+
[key: string]: any;
|
|
162
|
+
}
|
|
163
|
+
/** Runtime multi-level grouping state. */
|
|
164
|
+
export interface GroupConfig {
|
|
165
|
+
/** Ordered list of column keys to group by (multi-level). */
|
|
166
|
+
columnKeys: string[];
|
|
167
|
+
/**
|
|
168
|
+
* Expanded group paths. Each path is a stable string built from the sequence
|
|
169
|
+
* of grouping values, e.g. `"City=SF|Status=Open"`.
|
|
170
|
+
*/
|
|
171
|
+
expanded: Set<string>;
|
|
172
|
+
}
|
|
173
|
+
export interface SortConfig {
|
|
174
|
+
key: string | null;
|
|
175
|
+
direction: SortDirection;
|
|
176
|
+
}
|
|
177
|
+
export interface PaginationConfig {
|
|
178
|
+
enabled: boolean;
|
|
179
|
+
pageSize: number;
|
|
180
|
+
currentPage: number;
|
|
181
|
+
totalPages: number;
|
|
182
|
+
totalRows: number;
|
|
183
|
+
showPageSizeSelector?: boolean;
|
|
184
|
+
pageSizeOptions?: number[];
|
|
185
|
+
}
|
|
186
|
+
export interface ServerPaginationConfig {
|
|
187
|
+
enabled: boolean;
|
|
188
|
+
onPageChange: (page: number, pageSize: number) => Promise<void> | void;
|
|
189
|
+
onPageSizeChange?: (pageSize: number) => Promise<void> | void;
|
|
190
|
+
loading?: boolean;
|
|
191
|
+
totalRows: number;
|
|
192
|
+
}
|
|
193
|
+
/** Supported export file formats. */
|
|
194
|
+
export type ExportFormat = "csv" | "json" | "xlsx";
|
|
195
|
+
/** Export configuration for the grid toolbar. */
|
|
196
|
+
export interface ExportOptions {
|
|
197
|
+
/** Allowed export formats. Defaults to `["xlsx"]`. */
|
|
198
|
+
formats?: ExportFormat[];
|
|
199
|
+
/** Default filename without extension. Defaults to `"grid-data"`. */
|
|
200
|
+
filename?: string;
|
|
201
|
+
/** When `false`, export is disabled even if `showExport` is `true`. */
|
|
202
|
+
enabled?: boolean;
|
|
203
|
+
/** `"client"` processes data in the browser; `"server"` calls `onServerExport`. */
|
|
204
|
+
exportMode?: "client" | "server";
|
|
205
|
+
/**
|
|
206
|
+
* Called when `exportMode === "server"`.
|
|
207
|
+
* @param format Requested file format.
|
|
208
|
+
* @param exportSelected Whether only selected rows should be exported.
|
|
209
|
+
* @param selectedRowIds IDs of selected rows when `exportSelected` is `true`.
|
|
210
|
+
*/
|
|
211
|
+
onServerExport?: (format: "csv" | "json" | "xlsx", exportSelected: boolean, selectedRowIds?: Array<string | number>) => void;
|
|
212
|
+
}
|
|
213
|
+
/** Client/server pagination options passed to the `pagination` prop. */
|
|
214
|
+
export interface PaginationOptions {
|
|
215
|
+
enabled?: boolean;
|
|
216
|
+
mode?: PaginationMode;
|
|
217
|
+
pageSize?: number;
|
|
218
|
+
showPageSizeSelector?: boolean;
|
|
219
|
+
pageSizeOptions?: number[];
|
|
220
|
+
serverConfig?: ServerPaginationConfig;
|
|
221
|
+
}
|
|
222
|
+
/** Performance tuning knobs for large datasets. */
|
|
223
|
+
export interface PerformanceConfig {
|
|
224
|
+
/** Enable horizontal (column) virtualization. Default `true`. */
|
|
225
|
+
enableHorizontalVirtualization?: boolean;
|
|
226
|
+
/** Column count above which horizontal virtualization activates. Default `50`. */
|
|
227
|
+
horizontalVirtualizationThreshold?: number;
|
|
228
|
+
/** Row count above which sorting is offloaded to a Web Worker. Default `5000`. Set to `0` to disable. */
|
|
229
|
+
sortWorkerThreshold?: number;
|
|
230
|
+
/** Maximum search-cache size for global filtering. Default `5000`. */
|
|
231
|
+
maxFilterCacheSize?: number;
|
|
232
|
+
/** Enable aggressive memoization for large datasets. Default `true`. */
|
|
233
|
+
enableAggressiveMemoization?: boolean;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Configuration for infinite-scroll mode.
|
|
237
|
+
*
|
|
238
|
+
* When enabled, `pagination` is ignored and `PaginationControls` are hidden.
|
|
239
|
+
* The grid renders all rows currently in `data`; when the user scrolls near
|
|
240
|
+
* the bottom, `onLoadMore` is called so the parent can append more rows.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```tsx
|
|
244
|
+
* <KDGrid
|
|
245
|
+
* data={rows}
|
|
246
|
+
* columns={columns}
|
|
247
|
+
* infiniteScroll={{
|
|
248
|
+
* enabled: true,
|
|
249
|
+
* hasMore: page < totalPages,
|
|
250
|
+
* isLoading: isFetching,
|
|
251
|
+
* onLoadMore: () => setPage((p) => p + 1),
|
|
252
|
+
* }}
|
|
253
|
+
* />
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
export interface InfiniteScrollOptions {
|
|
257
|
+
/** Must be `true` to activate infinite scroll mode. */
|
|
258
|
+
enabled: boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Set to `false` when there are no more rows to fetch.
|
|
261
|
+
* The sentinel is disconnected immediately to prevent spurious calls.
|
|
262
|
+
*/
|
|
263
|
+
hasMore: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Set to `true` while rows are being fetched.
|
|
266
|
+
* Prevents `onLoadMore` being called again before the current fetch resolves.
|
|
267
|
+
*/
|
|
268
|
+
isLoading: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Called when the user scrolls near the bottom and `hasMore` is `true`.
|
|
271
|
+
* Append new rows to the `data` prop to display them.
|
|
272
|
+
*/
|
|
273
|
+
onLoadMore: () => void;
|
|
274
|
+
/**
|
|
275
|
+
* Pixels of root margin below the viewport that trigger `onLoadMore`.
|
|
276
|
+
* Higher values pre-fetch earlier. Default `250`.
|
|
277
|
+
*/
|
|
278
|
+
threshold?: number;
|
|
279
|
+
/**
|
|
280
|
+
* Custom renderer for the loading indicator shown at the bottom while
|
|
281
|
+
* `isLoading` is `true`. Defaults to a pulsing spinner row.
|
|
282
|
+
*/
|
|
283
|
+
loadingRenderer?: () => React.ReactNode;
|
|
284
|
+
}
|
|
285
|
+
export interface ContextMenuItem {
|
|
286
|
+
id: string;
|
|
287
|
+
label: string;
|
|
288
|
+
icon?: ReactNode;
|
|
289
|
+
onClick: (row: GridRow) => void;
|
|
290
|
+
disabled?: boolean;
|
|
291
|
+
/** Renders as a horizontal divider; `label` and `onClick` are ignored. */
|
|
292
|
+
separator?: boolean;
|
|
293
|
+
}
|
|
294
|
+
export interface BulkActionOption {
|
|
295
|
+
/**
|
|
296
|
+
* Unique identifier for this action.
|
|
297
|
+
* Open string type — add any custom id (e.g. `"approve"`, `"flag"`).
|
|
298
|
+
*/
|
|
299
|
+
id: string;
|
|
300
|
+
label: string;
|
|
301
|
+
icon: ReactNode;
|
|
302
|
+
onClick: (selectedRows: Set<string | number>) => void;
|
|
303
|
+
disabled?: boolean;
|
|
304
|
+
destructive?: boolean;
|
|
305
|
+
}
|
|
306
|
+
export interface SavedFilter {
|
|
307
|
+
id: string;
|
|
308
|
+
name: string;
|
|
309
|
+
globalFilter: string;
|
|
310
|
+
columnFilters: Record<string, ColumnFilterValue>;
|
|
311
|
+
searchMode: SearchMode;
|
|
312
|
+
}
|
|
313
|
+
export interface ServerFilterChangePayload {
|
|
314
|
+
globalFilter: string;
|
|
315
|
+
columnFilters: ActiveFilters;
|
|
316
|
+
filterableKeys: string[];
|
|
317
|
+
searchMode?: SearchMode;
|
|
318
|
+
}
|
|
319
|
+
export interface ColumnConfig {
|
|
320
|
+
columnWidths: Record<string, number>;
|
|
321
|
+
columnVisibility: Record<string, boolean>;
|
|
322
|
+
pinnedColumns: string[];
|
|
323
|
+
sortConfig: SortConfig;
|
|
324
|
+
/** Multi-level grouping state persisted to storage. */
|
|
325
|
+
groupConfig?: {
|
|
326
|
+
columnKeys?: string[];
|
|
327
|
+
};
|
|
328
|
+
filters: {
|
|
329
|
+
globalFilter: string;
|
|
330
|
+
columnFilters: ActiveFilters;
|
|
331
|
+
};
|
|
332
|
+
columnOrder?: string[];
|
|
333
|
+
density?: Density;
|
|
334
|
+
}
|
|
335
|
+
export interface RowEventParams {
|
|
336
|
+
row: GridRow;
|
|
337
|
+
event: MouseEvent;
|
|
338
|
+
}
|
|
339
|
+
export interface CellClickParams {
|
|
340
|
+
row: GridRow;
|
|
341
|
+
column: GridColumn;
|
|
342
|
+
value: any;
|
|
343
|
+
event: MouseEvent;
|
|
344
|
+
}
|
|
345
|
+
export interface CellContextMenuParams {
|
|
346
|
+
row: GridRow;
|
|
347
|
+
column: GridColumn;
|
|
348
|
+
value: any;
|
|
349
|
+
displayValue: string;
|
|
350
|
+
event: MouseEvent;
|
|
351
|
+
}
|
|
352
|
+
export interface CellFocusParams {
|
|
353
|
+
row: GridRow;
|
|
354
|
+
column: GridColumn;
|
|
355
|
+
value: any;
|
|
356
|
+
rowIndex: number;
|
|
357
|
+
colIndex: number;
|
|
358
|
+
}
|
|
359
|
+
export interface CellEditParams {
|
|
360
|
+
/** The row object being edited. */
|
|
361
|
+
row: GridRow;
|
|
362
|
+
/** The column being edited. */
|
|
363
|
+
column: GridColumn;
|
|
364
|
+
/** The previous (pre-edit) value. */
|
|
365
|
+
oldValue: any;
|
|
366
|
+
/** The committed new value. */
|
|
367
|
+
newValue: any;
|
|
368
|
+
/** Row id derived from `getRowId` or `row.id`. */
|
|
369
|
+
rowId: string | number;
|
|
370
|
+
}
|
|
371
|
+
export interface CellSelectionPayload {
|
|
372
|
+
bounds: {
|
|
373
|
+
rowStart: number;
|
|
374
|
+
rowEnd: number;
|
|
375
|
+
colStart: number;
|
|
376
|
+
colEnd: number;
|
|
377
|
+
} | null;
|
|
378
|
+
cells: Array<CellFocusParams>;
|
|
379
|
+
}
|
|
380
|
+
export interface CopyCellsPayload {
|
|
381
|
+
text: string;
|
|
382
|
+
bounds?: {
|
|
383
|
+
rowStart: number;
|
|
384
|
+
rowEnd: number;
|
|
385
|
+
colStart: number;
|
|
386
|
+
colEnd: number;
|
|
387
|
+
} | null;
|
|
388
|
+
cells: Array<CellFocusParams>;
|
|
389
|
+
isRectangular: boolean;
|
|
390
|
+
isFocusedCell: boolean;
|
|
391
|
+
}
|
|
392
|
+
export interface KDGridProps {
|
|
393
|
+
/**
|
|
394
|
+
* License key for the grid. The component will not render without a
|
|
395
|
+
* valid key. E.g. "kd_team_v3_xyz"
|
|
396
|
+
*/
|
|
397
|
+
licenseKey?: string;
|
|
398
|
+
data: GridRow[];
|
|
399
|
+
columns: GridColumn[];
|
|
400
|
+
/**
|
|
401
|
+
* Derive a unique row identifier from a row object.
|
|
402
|
+
*
|
|
403
|
+
* Priority:
|
|
404
|
+
* 1. `getRowId(row)` if provided
|
|
405
|
+
* 2. `row.id` if present
|
|
406
|
+
* 3. Row index (⚠️ may cause issues with pagination / filtering)
|
|
407
|
+
*/
|
|
408
|
+
getRowId?: (row: GridRow) => string | number;
|
|
409
|
+
/** Fixed height of the grid container in pixels. */
|
|
410
|
+
height?: number;
|
|
411
|
+
/** Row density. Default `"md"`. */
|
|
412
|
+
density?: Density;
|
|
413
|
+
onDensityChange?: (density: Density) => void;
|
|
414
|
+
/** Show a density toggle in the toolbar. */
|
|
415
|
+
showDensityControl?: boolean;
|
|
416
|
+
/** Override the header row height in pixels. Takes precedence over `headerDensity`. */
|
|
417
|
+
headerHeight?: number;
|
|
418
|
+
/** Independent density for the header row. */
|
|
419
|
+
headerDensity?: Density;
|
|
420
|
+
/**
|
|
421
|
+
* Minimum column width enforced during drag-resize.
|
|
422
|
+
* Prevents columns from being resized to an unusably narrow state.
|
|
423
|
+
* Default: `80` (px).
|
|
424
|
+
*/
|
|
425
|
+
minResizeWidth?: number;
|
|
426
|
+
rowHeight?: number;
|
|
427
|
+
overscan?: number;
|
|
428
|
+
/**
|
|
429
|
+
* When total post-filter rows ≤ this number, virtualization is disabled for
|
|
430
|
+
* simpler DOM. Default `300`.
|
|
431
|
+
*/
|
|
432
|
+
virtualizationThreshold?: number;
|
|
433
|
+
selectable?: boolean;
|
|
434
|
+
sortable?: boolean;
|
|
435
|
+
filterable?: boolean;
|
|
436
|
+
groupable?: boolean;
|
|
437
|
+
virtualized?: boolean;
|
|
438
|
+
/** Show a loading overlay / skeleton. Replaces `isLoading` from v2. */
|
|
439
|
+
loading?: boolean;
|
|
440
|
+
/** Text to show when there are no rows to display. */
|
|
441
|
+
noDataMessage?: string;
|
|
442
|
+
/** Fully custom empty-state renderer; overrides `noDataMessage`. */
|
|
443
|
+
noDataRenderer?: () => ReactNode;
|
|
444
|
+
showToolbar?: boolean;
|
|
445
|
+
showExport?: boolean;
|
|
446
|
+
exportOptions?: ExportOptions;
|
|
447
|
+
toolbarLeft?: ReactNode;
|
|
448
|
+
toolbarRight?: ReactNode;
|
|
449
|
+
onRefresh?: () => void;
|
|
450
|
+
/** Externally controlled selection ids (controlled mode). */
|
|
451
|
+
selectedRowIds?: Iterable<string | number> | null;
|
|
452
|
+
onRowSelect?: (row: GridRow) => void;
|
|
453
|
+
onSelectedRowsChange?: (selectedRows: Set<string | number>) => void;
|
|
454
|
+
/** Predicate; return `false` to make a specific row non-selectable. */
|
|
455
|
+
isRowSelectable?: (row: GridRow) => boolean;
|
|
456
|
+
bulkActions?: BulkActionOption[];
|
|
457
|
+
pagination?: PaginationOptions;
|
|
458
|
+
/**
|
|
459
|
+
* Enable infinite-scroll mode. Mutually exclusive with `pagination`.
|
|
460
|
+
* When enabled, `PaginationControls` are hidden and `onLoadMore` is
|
|
461
|
+
* called automatically when the user scrolls near the bottom.
|
|
462
|
+
*/
|
|
463
|
+
infiniteScroll?: InfiniteScrollOptions;
|
|
464
|
+
/**
|
|
465
|
+
* Controls how the global search bar matches text.
|
|
466
|
+
* Default `"contains"`.
|
|
467
|
+
*/
|
|
468
|
+
searchMode?: SearchMode;
|
|
469
|
+
/**
|
|
470
|
+
* @deprecated Not implemented. Will be removed in a future major version.
|
|
471
|
+
* Use `onFilterChange` + your own state to build a saved-filter UI.
|
|
472
|
+
*/
|
|
473
|
+
savedFilters?: SavedFilter[];
|
|
474
|
+
/**
|
|
475
|
+
* @deprecated Not implemented. Will be removed in a future major version.
|
|
476
|
+
*/
|
|
477
|
+
onSaveFilter?: (filter: Omit<SavedFilter, "id">) => void;
|
|
478
|
+
/**
|
|
479
|
+
* @deprecated Not implemented. Will be removed in a future major version.
|
|
480
|
+
*/
|
|
481
|
+
onLoadFilter?: (filter: SavedFilter) => void;
|
|
482
|
+
/**
|
|
483
|
+
* @deprecated Not implemented. Will be removed in a future major version.
|
|
484
|
+
*/
|
|
485
|
+
onDeleteFilter?: (filterId: string) => void;
|
|
486
|
+
/** Fired on every filter change — useful for server-side filtering. */
|
|
487
|
+
onFilterChange?: (payload: ServerFilterChangePayload) => void;
|
|
488
|
+
/**
|
|
489
|
+
* Called when the user sorts a column.
|
|
490
|
+
* `direction` is `null` when the sort is cleared.
|
|
491
|
+
*/
|
|
492
|
+
onSort?: (columnKey: string, direction: "asc" | "desc" | null) => void;
|
|
493
|
+
groupBarVisibility?: "hidden" | "auto" | "visible";
|
|
494
|
+
groupFooterVariant?: "chips" | "columns";
|
|
495
|
+
showGroupExpandControls?: boolean;
|
|
496
|
+
renderGroupActions?: (groupInfo: {
|
|
497
|
+
groupKey: string;
|
|
498
|
+
columnKey: string;
|
|
499
|
+
groupValue: any;
|
|
500
|
+
rows: GridRow[];
|
|
501
|
+
count: number;
|
|
502
|
+
level: number;
|
|
503
|
+
}) => ReactNode;
|
|
504
|
+
/** CSS class applied to each row — static string or derived from row + index. */
|
|
505
|
+
rowClassName?: string | ((row: GridRow, index: number) => string);
|
|
506
|
+
rowStyle?: (row: GridRow) => CSSProperties | undefined;
|
|
507
|
+
onRowClick?: (params: RowEventParams) => void;
|
|
508
|
+
onRowDoubleClick?: (params: RowEventParams) => void;
|
|
509
|
+
/** Right-click on a row (before the built-in context menu opens). */
|
|
510
|
+
onContextMenu?: (params: RowEventParams) => void;
|
|
511
|
+
/** Custom items for the row right-click context menu. */
|
|
512
|
+
contextMenuItems?: ContextMenuItem[];
|
|
513
|
+
onCellClick?: (params: CellClickParams) => void;
|
|
514
|
+
onCellContextMenu?: (params: CellContextMenuParams) => void;
|
|
515
|
+
/** Enable single-cell focus with arrow-key navigation. */
|
|
516
|
+
cellFocusEnabled?: boolean;
|
|
517
|
+
onCellFocusChange?: (params: CellFocusParams) => void;
|
|
518
|
+
/** Enable rectangular cell selection (disables browser text selection). */
|
|
519
|
+
cellSelectionEnabled?: boolean;
|
|
520
|
+
/** Return `false` to prevent a specific cell from being selected. */
|
|
521
|
+
canSelectCell?: (row: GridRow, column: GridColumn) => boolean;
|
|
522
|
+
onCellSelectionChange?: (payload: CellSelectionPayload) => void;
|
|
523
|
+
/**
|
|
524
|
+
* Called when the user copies cells with Ctrl/⌘+C while cell focus or
|
|
525
|
+
* rectangular selection is active.
|
|
526
|
+
*/
|
|
527
|
+
onCopyCells?: (payload: CopyCellsPayload) => void;
|
|
528
|
+
/**
|
|
529
|
+
* Fired after the user commits an edit (Enter / Tab / blur).
|
|
530
|
+
* Update your `data` prop here to reflect the change.
|
|
531
|
+
*/
|
|
532
|
+
onCellEdit?: (params: CellEditParams) => void;
|
|
533
|
+
/**
|
|
534
|
+
* Fired the moment an edit session opens (double-click or F2).
|
|
535
|
+
* Return `false` to veto the edit.
|
|
536
|
+
*/
|
|
537
|
+
onCellEditStart?: (params: {
|
|
538
|
+
row: GridRow;
|
|
539
|
+
column: GridColumn;
|
|
540
|
+
value: any;
|
|
541
|
+
}) => boolean | void;
|
|
542
|
+
onAutosizeColumn?: (columnKey: string) => void;
|
|
543
|
+
onAutosizeAllColumns?: () => void;
|
|
544
|
+
onResetColumns?: () => void;
|
|
545
|
+
onColumnConfigChange?: (config: ColumnConfig) => void;
|
|
546
|
+
initialColumnConfig?: Partial<ColumnConfig>;
|
|
547
|
+
performanceConfig?: PerformanceConfig;
|
|
548
|
+
/**
|
|
549
|
+
* When `true`, enables inline editing for **all** columns that do not
|
|
550
|
+
* explicitly set `editable: false`. Individual columns can still opt out
|
|
551
|
+
* by setting `editable: false` on their column definition.
|
|
552
|
+
*
|
|
553
|
+
* Columns that already have their own `editable` setting are unaffected.
|
|
554
|
+
*
|
|
555
|
+
* Pair with `onCellEdit` to receive the committed values.
|
|
556
|
+
*/
|
|
557
|
+
editable?: boolean;
|
|
558
|
+
}
|
|
559
|
+
export interface KDGridRef {
|
|
560
|
+
/** Replace the entire ordered grouping key list. */
|
|
561
|
+
setGroupKeys: (keys: string[]) => void;
|
|
562
|
+
/** Append a grouping key if not already present. */
|
|
563
|
+
addGroupKey: (key: string) => void;
|
|
564
|
+
/** Remove a specific grouping key. */
|
|
565
|
+
removeGroupKey: (key: string) => void;
|
|
566
|
+
/** Expand every group for the current grouping keys. */
|
|
567
|
+
expandAllGroups: () => void;
|
|
568
|
+
/** Collapse all groups. */
|
|
569
|
+
collapseAllGroups: () => void;
|
|
570
|
+
/** Toggle a specific group path, e.g. `"City=SF|Status=Open"`. */
|
|
571
|
+
toggleGroupExpansion: (groupPath: string) => void;
|
|
572
|
+
/** Read the current grouping configuration. */
|
|
573
|
+
getGroupConfig: () => GroupConfig;
|
|
574
|
+
/** Apply a column filter programmatically. Pass `null` to clear. */
|
|
575
|
+
setColumnFilter: (columnKey: string, filter: ColumnFilterValue | null) => void;
|
|
576
|
+
/** Clear a single column filter. */
|
|
577
|
+
clearColumnFilter: (columnKey: string) => void;
|
|
578
|
+
/** Clear all active filters (global + column). */
|
|
579
|
+
clearAllFilters: () => void;
|
|
580
|
+
/** Set the global search text. */
|
|
581
|
+
setGlobalFilter: (value: string) => void;
|
|
582
|
+
/**
|
|
583
|
+
* Scroll the grid body so that the row with the given id is visible.
|
|
584
|
+
* Falls back silently if the row is not found in the current view.
|
|
585
|
+
*/
|
|
586
|
+
scrollToRow: (rowId: string | number) => void;
|
|
587
|
+
/**
|
|
588
|
+
* Scroll the grid body so that the column with the given key is visible.
|
|
589
|
+
* Falls back silently if the column is not found.
|
|
590
|
+
*/
|
|
591
|
+
scrollToColumn: (columnKey: string) => void;
|
|
592
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal inline date utilities — replaces the date-fns dependency so
|
|
3
|
+
* consumers don't need to install date-fns to use KDGrid.
|
|
4
|
+
*
|
|
5
|
+
* We only use two operations from date-fns across the entire library:
|
|
6
|
+
* format(date, "yyyy-MM-dd") → toYMD(date)
|
|
7
|
+
* parse(str, "yyyy-MM-dd", referenceDate) → fromYMD(str)
|
|
8
|
+
*
|
|
9
|
+
* These ~20 lines are far cheaper than shipping a 30 KB peer dependency.
|
|
10
|
+
*/
|
|
11
|
+
/** Format a Date to "yyyy-MM-dd" (ISO date portion only). */
|
|
12
|
+
export declare const toYMD: (d: Date) => string;
|
|
13
|
+
/** Parse a "yyyy-MM-dd" string into a Date (local midnight). Returns Invalid Date on failure. */
|
|
14
|
+
export declare const fromYMD: (s: string) => Date;
|
|
15
|
+
/** Format a Date to human-readable "dd-MM-yyyy" for display. */
|
|
16
|
+
export declare const toDMY: (d: Date) => string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Highlights matching text within a string based on a search query
|
|
4
|
+
* @param text - The text to highlight
|
|
5
|
+
* @param searchQuery - The search query to match against
|
|
6
|
+
* @returns JSX element with highlighted matches
|
|
7
|
+
*/
|
|
8
|
+
export declare const highlightText: (text: string, searchQuery: string) => React.ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a value contains the search query (case-insensitive)
|
|
11
|
+
* @param value - The value to check
|
|
12
|
+
* @param searchQuery - The search query
|
|
13
|
+
* @returns true if the value contains the search query
|
|
14
|
+
*/
|
|
15
|
+
export declare const containsSearchQuery: (value: any, searchQuery: string) => boolean;
|