@smallwebco/tinypivot-react 1.0.12 → 1.0.14

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/dist/index.cjs CHANGED
@@ -67,13 +67,17 @@ function useExcelGrid(options) {
67
67
  const [columnVisibility, setColumnVisibility] = (0, import_react.useState)({});
68
68
  const [globalFilter, setGlobalFilter] = (0, import_react.useState)("");
69
69
  const [columnStatsCache, setColumnStatsCache] = (0, import_react.useState)({});
70
+ const dataSignature = (0, import_react.useMemo)(
71
+ () => `${Date.now()}-${Math.random().toString(36).slice(2)}`,
72
+ [data]
73
+ );
70
74
  const columnKeys = (0, import_react.useMemo)(() => {
71
75
  if (data.length === 0) return [];
72
76
  return Object.keys(data[0]);
73
77
  }, [data]);
74
78
  const getColumnStats = (0, import_react.useCallback)(
75
79
  (columnKey) => {
76
- const cacheKey = `${columnKey}-${data.length}`;
80
+ const cacheKey = `${columnKey}-${dataSignature}`;
77
81
  if (!columnStatsCache[cacheKey]) {
78
82
  const stats = (0, import_tinypivot_core.getColumnUniqueValues)(data, columnKey);
79
83
  setColumnStatsCache((prev) => ({ ...prev, [cacheKey]: stats }));
@@ -81,11 +85,14 @@ function useExcelGrid(options) {
81
85
  }
82
86
  return columnStatsCache[cacheKey];
83
87
  },
84
- [data, columnStatsCache]
88
+ [data, columnStatsCache, dataSignature]
85
89
  );
86
90
  const clearStatsCache = (0, import_react.useCallback)(() => {
87
91
  setColumnStatsCache({});
88
92
  }, []);
93
+ (0, import_react.useEffect)(() => {
94
+ clearStatsCache();
95
+ }, [dataSignature, clearStatsCache]);
89
96
  const columnDefs = (0, import_react.useMemo)(() => {
90
97
  return columnKeys.map((key) => {
91
98
  const stats = getColumnStats(key);
@@ -146,7 +153,6 @@ function useExcelGrid(options) {
146
153
  const column = table.getColumn(columnId);
147
154
  if (column) {
148
155
  column.setFilterValue(values.length === 0 ? void 0 : values);
149
- setColumnFilters(table.getState().columnFilters);
150
156
  }
151
157
  },
152
158
  [table]
@@ -1904,6 +1910,9 @@ function DataGrid({
1904
1910
  const end = start + pageSize;
1905
1911
  return searchFilteredData.slice(start, end);
1906
1912
  }, [enablePagination, searchFilteredData, currentPage, pageSize]);
1913
+ (0, import_react8.useEffect)(() => {
1914
+ setCurrentPage(1);
1915
+ }, [columnFilters, globalSearchTerm]);
1907
1916
  const selectionBounds = (0, import_react8.useMemo)(() => {
1908
1917
  if (!selectionStart || !selectionEnd) return null;
1909
1918
  return {