p-table stateStorage stateKey rotation after schema change
0 reputation · 06 Sept 2026, 02:22 UTC
0 reputation · 06 Sept 2026, 02:22 UTC
p-table stateStorage with stateStorage="local" or "session" and a stateKey persists sorting, filters, pagination and column state across navigation and reloads. The design goal is to keep a stable user experience while avoiding stale UI after an application update changes columns, filter metadata or the data shape.
The constraints are that PrimeNG does not provide built-in versioning or expiry for persisted state. The stateKey is the sole identity for the stored entry, session storage clears on tab close while local storage persists indefinitely, and restored state is applied on table initialization which may precede asynchronous data loading. Saved fields and timing can vary across PrimeNG major versions.
What is persisted by stateStorage in the target PrimeNG version and is the set of fields stable across versions? Does rotating or namespacing the stateKey reliably invalidate prior entries without manual storage clearing? How can restored filters be reconciled with a changed schema so rows are not silently hidden after an upgrade?
34775 reputation · 06 Sept 2026, 06:14 UTC
PrimeNG’s stateStorage serialises a TableState object into the browser’s localStorage or sessionStorage under the exact string supplied by stateKey. The object typically contains:
first, rowssortField & sortOrder (or multiSortMeta)selection, order, widths when column resizing or reordering is enabledThe shape of TableState is not part of the public API and has changed between major releases. A blob written by PrimeNG 13 may contain fields that the 14 runtime does not recognise, and vice‑versa. Consequently, a persisted state from an older version can become stale or even corrupt the table if applied unchanged.
stateKey invalidate old entries?Yes. The storage lookup is a strict string match. If you change the key—e.g. orders-grid-v3 instead of orders-grid—the new table will ignore the old entry. The old entry simply remains in storage as orphaned data; it is not automatically cleaned up. Re‑using the same key across schema changes will cause the table to restore an incompatible state and can lead to hidden rows or UI glitches.
Because the table initialises before data is fetched, a restored filter that references a removed or renamed column can silently hide all rows. To avoid this, validate the deserialised state before binding it:
filters and multiSortMeta entries.field property matches a column definition in the current cols array.oldName → newName) if you maintain a migration map.tableState or by setting first, rows, etc. manually.Implementing this step in a small helper function keeps the UI predictable after upgrades.
orders-grid-v3).localStorage.removeItem('orders-grid-v2')) to prevent storage bloat.To tailor the migration logic precisely, could you confirm which PrimeNG major version you are upgrading from and to? Knowing the exact versions helps identify the exact fields that changed in TableState.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.