@tint-ui/data-table 0.3.9 → 0.3.10
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/cjs/use-data-table.js +18 -0
- package/package.json +1 -1
- package/types.d.ts +1 -1
- package/use-data-table.js +18 -0
package/cjs/use-data-table.js
CHANGED
|
@@ -218,6 +218,8 @@ const useDataTable = function (props) {
|
|
|
218
218
|
const manual = refDataFn.current != null;
|
|
219
219
|
const hash = createHash(name, keyName, manual, tableCells);
|
|
220
220
|
const refHash = React.useRef(hash);
|
|
221
|
+
const refOptions = React.useRef(options);
|
|
222
|
+
refOptions.current = options;
|
|
221
223
|
const [data, setData] = React.useState(() => initialDataState(props.data, props.initialData));
|
|
222
224
|
const toolbar = (0, _utils.getToolbarConfig)(toolbarProp);
|
|
223
225
|
const navbar = (0, _utils.getNavbarConfig)(navbarProp, props.limit || defaultPageSize);
|
|
@@ -424,6 +426,10 @@ const useDataTable = function (props) {
|
|
|
424
426
|
});
|
|
425
427
|
},
|
|
426
428
|
onGlobalFilterChange(value) {
|
|
429
|
+
const cb = refOptions.current?.onGlobalFilterChange;
|
|
430
|
+
if (cb) {
|
|
431
|
+
cb(value);
|
|
432
|
+
}
|
|
427
433
|
setState(prev => {
|
|
428
434
|
if (prev.loading) {
|
|
429
435
|
return prev;
|
|
@@ -450,6 +456,10 @@ const useDataTable = function (props) {
|
|
|
450
456
|
});
|
|
451
457
|
},
|
|
452
458
|
onColumnFiltersChange(value) {
|
|
459
|
+
const cb = refOptions.current?.onColumnFiltersChange;
|
|
460
|
+
if (cb) {
|
|
461
|
+
cb(value);
|
|
462
|
+
}
|
|
453
463
|
setState(prev => {
|
|
454
464
|
if (prev.loading) {
|
|
455
465
|
return prev;
|
|
@@ -479,6 +489,10 @@ const useDataTable = function (props) {
|
|
|
479
489
|
});
|
|
480
490
|
},
|
|
481
491
|
onSortingChange(value) {
|
|
492
|
+
const cb = refOptions.current?.onSortingChange;
|
|
493
|
+
if (cb) {
|
|
494
|
+
cb(value);
|
|
495
|
+
}
|
|
482
496
|
setState(prev => {
|
|
483
497
|
if (prev.loading) {
|
|
484
498
|
return prev;
|
|
@@ -507,6 +521,10 @@ const useDataTable = function (props) {
|
|
|
507
521
|
});
|
|
508
522
|
},
|
|
509
523
|
onPaginationChange(value) {
|
|
524
|
+
const cb = refOptions.current?.onPaginationChange;
|
|
525
|
+
if (cb) {
|
|
526
|
+
cb(value);
|
|
527
|
+
}
|
|
510
528
|
setState(prev => {
|
|
511
529
|
if (prev.loading) {
|
|
512
530
|
return prev;
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type SelectedOption<TData> = OptionTrigger<TData> & {
|
|
|
32
32
|
};
|
|
33
33
|
export type DataTableToolbarSize = "sm" | "md" | "lg";
|
|
34
34
|
export type DataTableNavbarSize = "sm" | "md" | "lg";
|
|
35
|
-
export interface DataTableOptions<TData> extends Partial<Omit<TableOptions<TData>, "pageCount" | "getCoreRowModel" | "getPaginationRowModel" | "getFilteredRowModel" | "getSortedRowModel" | "globalFilterFn" | "
|
|
35
|
+
export interface DataTableOptions<TData> extends Partial<Omit<TableOptions<TData>, "pageCount" | "getCoreRowModel" | "getPaginationRowModel" | "getFilteredRowModel" | "getSortedRowModel" | "globalFilterFn" | "manualFiltering" | "manualSorting" | "manualPagination" | "data" | "columns" | "state">> {
|
|
36
36
|
state?: Partial<Omit<TableState, "columnVisibility" | "sorting" | "globalFilter" | "columnFilters" | "pagination">>;
|
|
37
37
|
}
|
|
38
38
|
export interface DataTableCoreProps<TData> extends FilterType<TData> {
|
package/use-data-table.js
CHANGED
|
@@ -208,6 +208,8 @@ const useDataTable = function (props) {
|
|
|
208
208
|
const manual = refDataFn.current != null;
|
|
209
209
|
const hash = createHash(name, keyName, manual, tableCells);
|
|
210
210
|
const refHash = React.useRef(hash);
|
|
211
|
+
const refOptions = React.useRef(options);
|
|
212
|
+
refOptions.current = options;
|
|
211
213
|
const [data, setData] = React.useState(() => initialDataState(props.data, props.initialData));
|
|
212
214
|
const toolbar = getToolbarConfig(toolbarProp);
|
|
213
215
|
const navbar = getNavbarConfig(navbarProp, props.limit || defaultPageSize);
|
|
@@ -418,6 +420,10 @@ const useDataTable = function (props) {
|
|
|
418
420
|
});
|
|
419
421
|
},
|
|
420
422
|
onGlobalFilterChange(value) {
|
|
423
|
+
const cb = refOptions.current?.onGlobalFilterChange;
|
|
424
|
+
if (cb) {
|
|
425
|
+
cb(value);
|
|
426
|
+
}
|
|
421
427
|
setState(prev => {
|
|
422
428
|
if (prev.loading) {
|
|
423
429
|
return prev;
|
|
@@ -445,6 +451,10 @@ const useDataTable = function (props) {
|
|
|
445
451
|
});
|
|
446
452
|
},
|
|
447
453
|
onColumnFiltersChange(value) {
|
|
454
|
+
const cb = refOptions.current?.onColumnFiltersChange;
|
|
455
|
+
if (cb) {
|
|
456
|
+
cb(value);
|
|
457
|
+
}
|
|
448
458
|
setState(prev => {
|
|
449
459
|
if (prev.loading) {
|
|
450
460
|
return prev;
|
|
@@ -475,6 +485,10 @@ const useDataTable = function (props) {
|
|
|
475
485
|
});
|
|
476
486
|
},
|
|
477
487
|
onSortingChange(value) {
|
|
488
|
+
const cb = refOptions.current?.onSortingChange;
|
|
489
|
+
if (cb) {
|
|
490
|
+
cb(value);
|
|
491
|
+
}
|
|
478
492
|
setState(prev => {
|
|
479
493
|
if (prev.loading) {
|
|
480
494
|
return prev;
|
|
@@ -504,6 +518,10 @@ const useDataTable = function (props) {
|
|
|
504
518
|
});
|
|
505
519
|
},
|
|
506
520
|
onPaginationChange(value) {
|
|
521
|
+
const cb = refOptions.current?.onPaginationChange;
|
|
522
|
+
if (cb) {
|
|
523
|
+
cb(value);
|
|
524
|
+
}
|
|
507
525
|
setState(prev => {
|
|
508
526
|
if (prev.loading) {
|
|
509
527
|
return prev;
|