@redsift/table 12.5.4-muiv8-alpha.4 → 12.5.4
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/_internal/StatefulDataGrid2.js +38 -15
- package/_internal/StatefulDataGrid2.js.map +1 -1
- package/index.d.ts +10 -0
- package/index.js +81 -11
- package/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -2372,8 +2372,13 @@ const getModelsParsedOrUpdateLocalStorage = (search, localStorageVersion, column
|
|
|
2372
2372
|
const decompressedSearch = decompressSearchParams(search);
|
|
2373
2373
|
// Convert from display format (dot notation) to internal format (bracket notation) if needed
|
|
2374
2374
|
const decodedSearch = getDecodedSearchFromUrl(decompressedSearch, columns);
|
|
2375
|
-
const
|
|
2376
|
-
const
|
|
2375
|
+
const decodedParams = new URLSearchParams(decodedSearch);
|
|
2376
|
+
const currentVersion = decodedParams.get('v');
|
|
2377
|
+
// Only treat as "new version reset" when the URL has params with a stale/missing version.
|
|
2378
|
+
// An empty URL should fall through to the localStorage branch of each getter so persisted
|
|
2379
|
+
// state is restored instead of being clobbered by defaults.
|
|
2380
|
+
const hasUrlState = Array.from(decodedParams.keys()).length > 0;
|
|
2381
|
+
const isNewVersion = hasUrlState && (!currentVersion || Number(currentVersion) !== localStorageVersion);
|
|
2377
2382
|
const {
|
|
2378
2383
|
localStorageFilters,
|
|
2379
2384
|
setLocalStorageFilters,
|
|
@@ -3319,23 +3324,41 @@ const StatefulDataGrid = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
3319
3324
|
}, [isDataSourceMode, onPaginationModelChange]);
|
|
3320
3325
|
|
|
3321
3326
|
// In dataSource mode, pagination changes from our custom pagination slots
|
|
3322
|
-
// (rendered outside MUI's pagination state)
|
|
3323
|
-
//
|
|
3324
|
-
//
|
|
3325
|
-
//
|
|
3326
|
-
//
|
|
3327
|
-
// because in pivot/GroupedData strategy mode (and with paginationModel
|
|
3328
|
-
// passed via initialState rather than as a controlled prop) MUI does
|
|
3329
|
-
// not consistently fire the prop callback. The deep-equal guard in
|
|
3330
|
-
// useStatefulTable.onPaginationModelChange dedupes any re-emit MUI
|
|
3331
|
-
// does fire, so this is safe to call unconditionally.
|
|
3327
|
+
// (rendered outside MUI's pagination state) route through apiRef so MUI's
|
|
3328
|
+
// internal page state updates and dataSource.getRows() refetches with the
|
|
3329
|
+
// new params. The `paginationModelChange` subscription below picks up the
|
|
3330
|
+
// resulting state change and propagates it to URL/localStorage and local
|
|
3331
|
+
// React state via wrappedOnPaginationModelChange.
|
|
3332
3332
|
const dataSourcePaginationChange = useCallback(model => {
|
|
3333
3333
|
var _apiRef$current;
|
|
3334
3334
|
(_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.setPaginationModel(model);
|
|
3335
|
-
|
|
3336
|
-
|
|
3335
|
+
}, [apiRef]);
|
|
3336
|
+
|
|
3337
|
+
// In dataSource mode, subscribe to MUI's `paginationModelChange` event so
|
|
3338
|
+
// URL state stays in sync with MUI's internal pagination regardless of how
|
|
3339
|
+
// it changed (slot click, apiRef.setPaginationModel from consumer code,
|
|
3340
|
+
// MUI internal updates, etc.). Relying on MUI's `onPaginationModelChange`
|
|
3341
|
+
// prop callback alone is not sufficient: in pivot/GroupedData strategy mode
|
|
3342
|
+
// and with `paginationModel` seeded via `initialState` (rather than as a
|
|
3343
|
+
// controlled prop), the prop callback can be missed under certain
|
|
3344
|
+
// re-render orderings. The event fires reliably whenever the internal
|
|
3345
|
+
// state changes via `setState('setPaginationModel')`, see
|
|
3346
|
+
// `useGridStateInitialization.setState` → `publishEvent(changeEvent, …)`.
|
|
3347
|
+
// The deep-equal guard inside `useStatefulTable.onPaginationModelChange`
|
|
3348
|
+
// dedupes any duplicate emits, so overlap with the prop callback is safe.
|
|
3349
|
+
useEffect(() => {
|
|
3350
|
+
if (!isDataSourceMode) return;
|
|
3351
|
+
const api = apiRef.current;
|
|
3352
|
+
if (!(api !== null && api !== void 0 && api.subscribeEvent)) return;
|
|
3353
|
+
return api.subscribeEvent('paginationModelChange', model => {
|
|
3354
|
+
wrappedOnPaginationModelChange({
|
|
3355
|
+
page: model.page,
|
|
3356
|
+
pageSize: model.pageSize
|
|
3357
|
+
}, {
|
|
3358
|
+
reason: 'paginationModelChange'
|
|
3359
|
+
});
|
|
3337
3360
|
});
|
|
3338
|
-
}, [apiRef, wrappedOnPaginationModelChange]);
|
|
3361
|
+
}, [isDataSourceMode, apiRef, wrappedOnPaginationModelChange]);
|
|
3339
3362
|
const [rowSelectionModel, setRowSelectionModel] = useState(() => normalizeRowSelectionModel(propsRowSelectionModel));
|
|
3340
3363
|
useEffect(() => {
|
|
3341
3364
|
setRowSelectionModel(normalizeRowSelectionModel(propsRowSelectionModel));
|