@tint-ui/data-table 0.3.11 → 0.3.12

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.
@@ -20,7 +20,8 @@ var _utils = require("./utils");
20
20
  const _excluded = ["globalFilter"],
21
21
  _excluded2 = ["columnFilters"],
22
22
  _excluded3 = ["sorting"],
23
- _excluded4 = ["pagination"];
23
+ _excluded4 = ["pagination"],
24
+ _excluded5 = ["onFilterReset", "state"];
24
25
  const createHash = function (name, keyName, manual, cells) {
25
26
  let hash = `${name}[${keyName},${manual ? "1" : "0"}]://`;
26
27
  for (const cell of cells) {
@@ -388,10 +389,14 @@ const useDataTable = function (props) {
388
389
  if (!mount) {
389
390
  return;
390
391
  }
392
+ const cb = refOptions.current?.onFilterReset;
391
393
  setState(prev => {
392
394
  if (prev.loading) {
393
395
  return prev;
394
396
  }
397
+ if (cb) {
398
+ cb();
399
+ }
395
400
  const state = Object.assign({}, prev, {
396
401
  pagination: {
397
402
  pageSize: prev.pagination.pageSize,
@@ -408,15 +413,20 @@ const useDataTable = function (props) {
408
413
  });
409
414
  },
410
415
  onPageSizeChange(pageSize) {
416
+ const cb = refOptions.current?.onPaginationChange;
411
417
  setState(prev => {
412
418
  if (prev.loading || prev.pagination.pageSize === pageSize) {
413
419
  return prev;
414
420
  }
421
+ const paginationState = {
422
+ pageSize,
423
+ pageIndex: 0
424
+ };
425
+ if (cb) {
426
+ cb(paginationState);
427
+ }
415
428
  const state = Object.assign({}, prev, {
416
- pagination: {
417
- pageSize,
418
- pageIndex: 0
419
- }
429
+ pagination: paginationState
420
430
  });
421
431
  if (force(state)) {
422
432
  state.loading = true;
@@ -723,10 +733,22 @@ const useDataTable = function (props) {
723
733
  }
724
734
  };
725
735
  }, [onRowClick, loading]);
736
+ let optProp = {};
737
+ let optState = {};
738
+ if (options != null) {
739
+ const {
740
+ state
741
+ } = options,
742
+ prop = (0, _objectWithoutPropertiesLoose2.default)(options, _excluded5);
743
+ optProp = prop;
744
+ if (state) {
745
+ optState = state;
746
+ }
747
+ }
726
748
  const {
727
749
  pagination
728
750
  } = state;
729
- const tableCtx = (0, _reactTable.useReactTable)(Object.assign({}, options, {
751
+ const tableCtx = (0, _reactTable.useReactTable)(Object.assign({}, optProp, {
730
752
  pageCount: manual ? state.pageCount : undefined,
731
753
  getCoreRowModel: (0, _reactTable.getCoreRowModel)(),
732
754
  getPaginationRowModel: (0, _reactTable.getPaginationRowModel)(),
@@ -741,7 +763,7 @@ const useDataTable = function (props) {
741
763
  manualFiltering: manual,
742
764
  manualSorting: manual,
743
765
  manualPagination: manual,
744
- state: Object.assign({}, options?.state || null, {
766
+ state: Object.assign({}, optState, {
745
767
  columnVisibility,
746
768
  sorting: state.sorting,
747
769
  globalFilter: state.globalFilter,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tint-ui/data-table",
3
- "version": "0.3.11",
3
+ "version": "0.3.12",
4
4
  "author": "phragon@websoftlab.com",
5
5
  "license": "MIT",
6
6
  "dependencies": {
package/types.d.ts CHANGED
@@ -34,6 +34,7 @@ export type DataTableToolbarSize = "sm" | "md" | "lg";
34
34
  export type DataTableNavbarSize = "sm" | "md" | "lg";
35
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
+ onFilterReset?: () => void;
37
38
  }
38
39
  export interface DataTableCoreProps<TData> extends FilterType<TData> {
39
40
  table: DataTableType<TData>;
@@ -1,3 +1,3 @@
1
- import { DataTableCoreProps, DataTableContextType } from "./types";
1
+ import type { DataTableCoreProps, DataTableContextType } from "./types";
2
2
  declare const useDataTable: <TData extends object>(props: DataTableCoreProps<TData>) => DataTableContextType<TData>;
3
3
  export { useDataTable };
package/use-data-table.js CHANGED
@@ -380,10 +380,14 @@ const useDataTable = function (props) {
380
380
  if (!mount) {
381
381
  return;
382
382
  }
383
+ const cb = refOptions.current?.onFilterReset;
383
384
  setState(prev => {
384
385
  if (prev.loading) {
385
386
  return prev;
386
387
  }
388
+ if (cb) {
389
+ cb();
390
+ }
387
391
  const state = {
388
392
  ...prev,
389
393
  pagination: {
@@ -401,16 +405,21 @@ const useDataTable = function (props) {
401
405
  });
402
406
  },
403
407
  onPageSizeChange(pageSize) {
408
+ const cb = refOptions.current?.onPaginationChange;
404
409
  setState(prev => {
405
410
  if (prev.loading || prev.pagination.pageSize === pageSize) {
406
411
  return prev;
407
412
  }
413
+ const paginationState = {
414
+ pageSize,
415
+ pageIndex: 0
416
+ };
417
+ if (cb) {
418
+ cb(paginationState);
419
+ }
408
420
  const state = {
409
421
  ...prev,
410
- pagination: {
411
- pageSize,
412
- pageIndex: 0
413
- }
422
+ pagination: paginationState
414
423
  };
415
424
  if (force(state)) {
416
425
  state.loading = true;
@@ -721,11 +730,24 @@ const useDataTable = function (props) {
721
730
  }
722
731
  };
723
732
  }, [onRowClick, loading]);
733
+ let optProp = {};
734
+ let optState = {};
735
+ if (options != null) {
736
+ const {
737
+ onFilterReset,
738
+ state,
739
+ ...prop
740
+ } = options;
741
+ optProp = prop;
742
+ if (state) {
743
+ optState = state;
744
+ }
745
+ }
724
746
  const {
725
747
  pagination
726
748
  } = state;
727
749
  const tableCtx = useReactTable({
728
- ...options,
750
+ ...optProp,
729
751
  pageCount: manual ? state.pageCount : undefined,
730
752
  getCoreRowModel: getCoreRowModel(),
731
753
  getPaginationRowModel: getPaginationRowModel(),
@@ -741,7 +763,7 @@ const useDataTable = function (props) {
741
763
  manualSorting: manual,
742
764
  manualPagination: manual,
743
765
  state: {
744
- ...(options?.state || null),
766
+ ...optState,
745
767
  columnVisibility,
746
768
  sorting: state.sorting,
747
769
  globalFilter: state.globalFilter,