Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Grid State & Presets

index

Demo

Look at your developer console before leaving the page

Regular grid

Demo Page / Demo Component

with Backend Service

Demo Page / Demo Component

Descriptions

Grid State

The Grid State are what we defined as the currently used Columns / Filters / Sorters / Pagination / permanent Pinning of the actual grid (pagination is only returned when used in combo with the Backend Service API).

Presets

Presets can be used to preset a grid with certain Columns / Filters / Sorters / Pagination / permanent Pinning. When we say Columns, we actually mean their size, order position, visibility (shown/hidden) in the grid. Permanent pinning is stored separately under pinning.

Combining the two together

So basically, the idea is to save the Grid State in Local Storage (or DB) before the grid gets destroyed and once we come back to that same page we can preset the grid with the exact same state as it was before leaving the page (just like if we were doing a forward/back button with browser history).

Grid State

You can get the Grid State at any point in time. However if you wish to save the grid state before leaving the page and store that in Local Storage, then the best way is to use the detached() of your ViewModel.

View

ViewModel

Note since v10 you can now pass true as the argument to gridStateService.getCurrentGridState(true) which will return all columns, not just the visible columns but also include the hidden columns and their "hidden" properties.

Using Grid Presets & Filter SearchTerm(s)

What happens when we use the grid presets and a Filter Default SearchTerms? In this case, the presets will win over filter searchTerms. The cascading order of priorities is the following

  1. Do we have any presets? Yes use them, else go to step 2

  2. Do we have any Filter searchTerms? Yes use them, else go to step 3

  3. No presets and no searchTerms, load grid with default grid & column definitions

Grid Presets

Structure

The current structure of a Grid Presets is the following

GridState and GridOption.presets use the same structure. All permanent pinning is stored under pinning: columns.left/right identifies pinned columns, and rows.top/bottom identifies pinned rows. CurrentColumn entries store the column layout (order, width, visibility, and CSS classes) without repeating pinning.

Pinning values returned by Grid State

The pinning value returned by getCurrentGridState() (also returned directly by getCurrentPinning()) always includes all four side arrays: columns.left, columns.right, rows.top, and rows.bottom. Empty sides return [].

  • Column arrays contain string Column.id values. Numeric column IDs are converted to strings (for example, id: 42 is saved as '42'), because bare numbers in a column pinning array are interpreted as indexes. Presets can accept numeric column boundaries/counts or arrays of IDs/indexes, but returned state always contains the resolved string ID arrays.

  • Row arrays preserve their configured references: a number identifies a zero-based row index, a string identifies a dataset ID, and { id: number | string } explicitly identifies a dataset ID. Use the object form for numeric dataset IDs. Dataset IDs use datasetIdPropertyName (default id). ID references follow the same record through sorting and filtering; index references remain positional. Row references are not converted to indexes when saving state.

For example, the returned pinning value can be:

The Column.pinned option remains available on column definitions; its effective side is saved as a column ID under pinning.columns.left/right. When restoring state dynamically, apply the column layout first, then pass the saved pinning value to gridService.setPinning() when present. This uses the restored column order and visibility. Use empty arrays for all four sides to clear pinning.

Sticky columns and rows are configured through Column.sticky and GridOption.stickyRows. Their active membership depends on scroll position and is not included in saved Grid State or presets.

See the v11 migration guide when migrating saved state from the old frozen-property shape.

You can get Grouping column Ids as Grid State but it is limited to Draggable Grouping only via Grid Presets and it will not work with regular Grouping.

Example

For example, we can set presets on a grid like so:

View

ViewModel

Grid State Events

You can subscribe to GridState Service dispatched event

Examples

onGridStateServiceChanged dispatched event

View

ViewModel

View - SalesForce (ES6)

How to Load Grid with certain Columns Preset (example hide certain Column(s) on load)

You can show/hide or even change a column position via the presets, yes presets is that powerful. All you need to do is to pass all Columns that you want to show as part of the columns property of presets. Typically you already have the entire columns definition since you just defined it, so you can loop through it and just use map to list the columns according to the structure needed (see preset structure). What you have to know is that whatever array you provide to presets, that will equal to what the user will see and also in which order the columns will show (the array order does matter in this case). If a Columns is omitted from that array, then it will be considered to be a hidden column (you can still show it through Grid Menu and/or Column Picker).

So let say that we want to hide the last Column on page load, we can just find the column by it's id that you want to hide and pass the new column definition to the presets (again make sure to follow the correct preset structure).

Option 1

Pass the Grid Presets with an array that has less presets.columns, whichever column(s) are missing will be considered hidden columns

This would be the easiest way to do it.

Option 2

Since v10, the second alternative is to pass all the columns to presets.columns with some of them having the hidden properties. Both approaches are valid in v10, just choose whichever option you prefer.

Summary

As pointed out earlier, the presets requires a specific structure where the columns is the list of columns to show/hide with their possible widths. Also worth mentioning again that the position in the array is very important as it defines the position shown in the UI.

ViewModel

You could technically redefine by hand the complete list of columns that the presets requires. I would personally do it via the Column Definitions looping with map(), but loading them manually is also perfectly fine. You would just re-declare the columns again with the id and width (maybe include the hidden prop as well) and that would work as well.

Last updated