Managing grid state

Each grid has a state (based on the class Loki\AdminComponents\Grid\State) which keeps track of the current page, limit, search and possibly other parameters. The state is simply saved to the admin session.

Using state

Do not inject the class Loki\AdminComponents\Grid\State directly, because this will cause singleton behaviour where your grid will potentially share session data with another grid. Instead, inject Loki\AdminComponents\Grid\StateManager and use its get(string $namespace):State method to fetch the state that belongs to your namespace.

If you want to use additional parameters, just call upon the Loki\AdminComponents\Grid\State methods get() and save() to retrieve and/or store your parameter.

Namespacing your grid

By default, the block its layout name (which is unique) is used to set the namespace of a grid block. For example, in the case of this documentation, the namespace is set to yireo-training.example-admin.grid.

<block name="yireo-training.example-admin.grid" [...]>[...]</block>

However, you can also override this with the block argument namespace. This can be handy, because within the Loki_AdminComponents logic, the namespace is also used to retrieved stored UI bookmark configurations (as managed by the Magento core). In the example below, the namespace is set to product_listing, which makes sure that values like column ordering are shared between this Loki AdminComponents grid and the regular Magento products grid:

<block name="yireo-training.example-admin.grid" [...]>
    <arguments>
        <argument name="namespace" xsi:type="string">product_listing</argument>
    </arguments>
</block>
Last modified: September 1, 2025