Interface TableStateIf

The state of a table as plain JSON: column layout, sorting, scroll position, tree, checked and selected rows, header groups and data of your own. Get it with TableApi.getState, apply it with TableApi.applyState or pass it at the start as TableOptionsIf.initialState – e.g. to store it on your server per user. TableOptionsIf.autoRestoreOptions stores it in localStorage for you.

Every part is optional: a missing part is not applied (the table keeps its current state of that part). Columns are identified by their property, rows by their id (AutoRestoreOptionsIf.getRowId) – never by an index, so the state survives moved columns and rows that arrive in another order. Unknown columns and rows are ignored. The state holds no cell values – but row ids can be personal data (e.g. an e-mail address as id).

Example

const state: TableStateIf = tableApi.getState();
localStorage.setItem("orders-layout", JSON.stringify(state));
// later, e.g. in another table:
tableApi.applyState(JSON.parse(localStorage.getItem("orders-layout")!) as TableStateIf);

Example

// hand-written: "total" first and 240 px wide, "city" hidden, sorted by total descending
const state: TableStateIf = {
version: 1,
columns: [{ property: "total", width: 240 }, { property: "id" }, { property: "city", visible: false }],
sort: [{ property: "total", sortState: "desc" }]
};

See

Training: Remember the state

Since

1.1.92

Hierarchy

  • TableStateIf

Properties

checkedRowIds?: TableStateRowId[]

The ids of the checked rows.

columns?: TableColumnStateIf[]

The columns in their order (fixed columns included). Columns of the table that are missing here keep their place; unknown properties are ignored.

custom?: unknown

Data of your application, e.g. the text of a filter field (must be JSON).

detailRowIds?: TableStateRowId[]

The ids of the master rows with an expanded detail row (master/detail).

Since

1.1.97

headerGroups?: TableHeaderGroupStateIf[]

The state of the header groups with a toggle.

The scroll position.

The selection.

The sorted columns, the first one is the primary sort key. [] = unsorted.

Expanded / collapsed nodes of a tree table.

version: 1

Format version, always 1.