@tint-ui/data-table 0.3.9 → 0.3.11
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 +22 -2
- package/package.json +1 -1
- package/types.d.ts +1 -1
- package/use-data-table.js +22 -2
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,7 @@ const useDataTable = function (props) {
|
|
|
424
426
|
});
|
|
425
427
|
},
|
|
426
428
|
onGlobalFilterChange(value) {
|
|
429
|
+
const cb = refOptions.current?.onGlobalFilterChange;
|
|
427
430
|
setState(prev => {
|
|
428
431
|
if (prev.loading) {
|
|
429
432
|
return prev;
|
|
@@ -435,6 +438,9 @@ const useDataTable = function (props) {
|
|
|
435
438
|
if (typeof value === "function") {
|
|
436
439
|
value = value(globalFilter);
|
|
437
440
|
}
|
|
441
|
+
if (cb) {
|
|
442
|
+
cb(value);
|
|
443
|
+
}
|
|
438
444
|
const state = Object.assign({}, rest, {
|
|
439
445
|
pagination: {
|
|
440
446
|
pageSize: prev.pagination.pageSize,
|
|
@@ -450,6 +456,7 @@ const useDataTable = function (props) {
|
|
|
450
456
|
});
|
|
451
457
|
},
|
|
452
458
|
onColumnFiltersChange(value) {
|
|
459
|
+
const cb = refOptions.current?.onColumnFiltersChange;
|
|
453
460
|
setState(prev => {
|
|
454
461
|
if (prev.loading) {
|
|
455
462
|
return prev;
|
|
@@ -464,6 +471,9 @@ const useDataTable = function (props) {
|
|
|
464
471
|
value = value.filter(({
|
|
465
472
|
value
|
|
466
473
|
}) => Array.isArray(value) ? value.length > 0 : value != null && value !== "");
|
|
474
|
+
if (cb) {
|
|
475
|
+
cb(value);
|
|
476
|
+
}
|
|
467
477
|
const state = Object.assign({}, rest, {
|
|
468
478
|
pagination: {
|
|
469
479
|
pageSize: prev.pagination.pageSize,
|
|
@@ -479,6 +489,7 @@ const useDataTable = function (props) {
|
|
|
479
489
|
});
|
|
480
490
|
},
|
|
481
491
|
onSortingChange(value) {
|
|
492
|
+
const cb = refOptions.current?.onSortingChange;
|
|
482
493
|
setState(prev => {
|
|
483
494
|
if (prev.loading) {
|
|
484
495
|
return prev;
|
|
@@ -487,13 +498,17 @@ const useDataTable = function (props) {
|
|
|
487
498
|
sorting
|
|
488
499
|
} = prev,
|
|
489
500
|
rest = (0, _objectWithoutPropertiesLoose2.default)(prev, _excluded3);
|
|
501
|
+
const sortingState = typeof value === "function" ? value(sorting) : value;
|
|
502
|
+
if (cb) {
|
|
503
|
+
cb(sortingState);
|
|
504
|
+
}
|
|
490
505
|
const state = Object.assign({}, rest, {
|
|
491
506
|
pagination: {
|
|
492
507
|
pageSize: prev.pagination.pageSize,
|
|
493
508
|
pageIndex: 0
|
|
494
509
|
},
|
|
495
510
|
error: null,
|
|
496
|
-
sorting:
|
|
511
|
+
sorting: sortingState,
|
|
497
512
|
loading: false
|
|
498
513
|
});
|
|
499
514
|
if (force(state)) {
|
|
@@ -507,6 +522,7 @@ const useDataTable = function (props) {
|
|
|
507
522
|
});
|
|
508
523
|
},
|
|
509
524
|
onPaginationChange(value) {
|
|
525
|
+
const cb = refOptions.current?.onPaginationChange;
|
|
510
526
|
setState(prev => {
|
|
511
527
|
if (prev.loading) {
|
|
512
528
|
return prev;
|
|
@@ -515,8 +531,12 @@ const useDataTable = function (props) {
|
|
|
515
531
|
pagination
|
|
516
532
|
} = prev,
|
|
517
533
|
rest = (0, _objectWithoutPropertiesLoose2.default)(prev, _excluded4);
|
|
534
|
+
const paginationState = typeof value === "function" ? value(pagination) : value;
|
|
535
|
+
if (cb) {
|
|
536
|
+
cb(paginationState);
|
|
537
|
+
}
|
|
518
538
|
const state = Object.assign({}, rest, {
|
|
519
|
-
pagination:
|
|
539
|
+
pagination: paginationState,
|
|
520
540
|
error: null,
|
|
521
541
|
loading: false
|
|
522
542
|
});
|
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,7 @@ const useDataTable = function (props) {
|
|
|
418
420
|
});
|
|
419
421
|
},
|
|
420
422
|
onGlobalFilterChange(value) {
|
|
423
|
+
const cb = refOptions.current?.onGlobalFilterChange;
|
|
421
424
|
setState(prev => {
|
|
422
425
|
if (prev.loading) {
|
|
423
426
|
return prev;
|
|
@@ -429,6 +432,9 @@ const useDataTable = function (props) {
|
|
|
429
432
|
if (typeof value === "function") {
|
|
430
433
|
value = value(globalFilter);
|
|
431
434
|
}
|
|
435
|
+
if (cb) {
|
|
436
|
+
cb(value);
|
|
437
|
+
}
|
|
432
438
|
const state = {
|
|
433
439
|
...rest,
|
|
434
440
|
pagination: {
|
|
@@ -445,6 +451,7 @@ const useDataTable = function (props) {
|
|
|
445
451
|
});
|
|
446
452
|
},
|
|
447
453
|
onColumnFiltersChange(value) {
|
|
454
|
+
const cb = refOptions.current?.onColumnFiltersChange;
|
|
448
455
|
setState(prev => {
|
|
449
456
|
if (prev.loading) {
|
|
450
457
|
return prev;
|
|
@@ -459,6 +466,9 @@ const useDataTable = function (props) {
|
|
|
459
466
|
value = value.filter(({
|
|
460
467
|
value
|
|
461
468
|
}) => Array.isArray(value) ? value.length > 0 : value != null && value !== "");
|
|
469
|
+
if (cb) {
|
|
470
|
+
cb(value);
|
|
471
|
+
}
|
|
462
472
|
const state = {
|
|
463
473
|
...rest,
|
|
464
474
|
pagination: {
|
|
@@ -475,6 +485,7 @@ const useDataTable = function (props) {
|
|
|
475
485
|
});
|
|
476
486
|
},
|
|
477
487
|
onSortingChange(value) {
|
|
488
|
+
const cb = refOptions.current?.onSortingChange;
|
|
478
489
|
setState(prev => {
|
|
479
490
|
if (prev.loading) {
|
|
480
491
|
return prev;
|
|
@@ -483,6 +494,10 @@ const useDataTable = function (props) {
|
|
|
483
494
|
sorting,
|
|
484
495
|
...rest
|
|
485
496
|
} = prev;
|
|
497
|
+
const sortingState = typeof value === "function" ? value(sorting) : value;
|
|
498
|
+
if (cb) {
|
|
499
|
+
cb(sortingState);
|
|
500
|
+
}
|
|
486
501
|
const state = {
|
|
487
502
|
...rest,
|
|
488
503
|
pagination: {
|
|
@@ -490,7 +505,7 @@ const useDataTable = function (props) {
|
|
|
490
505
|
pageIndex: 0
|
|
491
506
|
},
|
|
492
507
|
error: null,
|
|
493
|
-
sorting:
|
|
508
|
+
sorting: sortingState,
|
|
494
509
|
loading: false
|
|
495
510
|
};
|
|
496
511
|
if (force(state)) {
|
|
@@ -504,6 +519,7 @@ const useDataTable = function (props) {
|
|
|
504
519
|
});
|
|
505
520
|
},
|
|
506
521
|
onPaginationChange(value) {
|
|
522
|
+
const cb = refOptions.current?.onPaginationChange;
|
|
507
523
|
setState(prev => {
|
|
508
524
|
if (prev.loading) {
|
|
509
525
|
return prev;
|
|
@@ -512,9 +528,13 @@ const useDataTable = function (props) {
|
|
|
512
528
|
pagination,
|
|
513
529
|
...rest
|
|
514
530
|
} = prev;
|
|
531
|
+
const paginationState = typeof value === "function" ? value(pagination) : value;
|
|
532
|
+
if (cb) {
|
|
533
|
+
cb(paginationState);
|
|
534
|
+
}
|
|
515
535
|
const state = {
|
|
516
536
|
...rest,
|
|
517
|
-
pagination:
|
|
537
|
+
pagination: paginationState,
|
|
518
538
|
error: null,
|
|
519
539
|
loading: false
|
|
520
540
|
};
|