Customization: State Persistence - Datatables for Laravel                  [               Datatables for Laravel  ](/) 

  Toggle main menu         [Docs](https://laravel-datatables.com/docs) [Demos](/demos) [Blog](https://laravel-datatables.com/blog) [Pricing](/pricing)        Search  ⌘ K   [ Log in ](/login) 

  [Docs](https://laravel-datatables.com/docs) [Demos](/demos) [Blog](https://laravel-datatables.com/blog) [Pricing](/pricing) 

 Search docs and demos  

Type at least 2 characters to search.

    Documentation menu      ### Getting Started

- [ Installation ](https://laravel-datatables.com/docs)
- [ Dark Mode ](https://laravel-datatables.com/docs/dark-mode)

### Basics

- [ Creating a Table ](https://laravel-datatables.com/docs/creating-a-table)
- [ Displaying Columns ](https://laravel-datatables.com/docs/displaying-columns)
- [ Data Sources ](https://laravel-datatables.com/docs/data-sources)
- [ Internationalisation ](https://laravel-datatables.com/docs/internationalisation)
- [ Multi-Language ](https://laravel-datatables.com/docs/multi-language)
- [ Styling ](https://laravel-datatables.com/docs/styling)

### Customization

- [ Columns ](https://laravel-datatables.com/docs/customization-columns)
- [ Cell Renderer ](https://laravel-datatables.com/docs/customization-cell-renderer)
- [ Value Formatter ](https://laravel-datatables.com/docs/customization-value-formatter)
- [ Filters ](https://laravel-datatables.com/docs/customization-filters)
- [ Pagination ](https://laravel-datatables.com/docs/customization-pagination)
- [ Sorting Icons ](https://laravel-datatables.com/docs/customization-sorting-icons)
- [ Row Actions ](https://laravel-datatables.com/docs/customization-row-actions)
- [ Multi Row Actions ](https://laravel-datatables.com/docs/customization-multi-row-actions)
- [ Loading Indicator ](https://laravel-datatables.com/docs/customization-loading-indicator)
- [ Exporting ](https://laravel-datatables.com/docs/customization-exporting)
- [ Components ](https://laravel-datatables.com/docs/customization-components)
- [ Data Sources ](https://laravel-datatables.com/docs/customization-data-sources)
- [ State Persistence ](https://laravel-datatables.com/docs/customization-state-persistence)

### Features

- [ Accessibility ](https://laravel-datatables.com/docs/feature-accessibility)
- [ Actions and Forms ](https://laravel-datatables.com/docs/actions-and-forms)
- [ Aggregate Columns ](https://laravel-datatables.com/docs/feature-aggregate-columns)
- [ Column Reordering ](https://laravel-datatables.com/docs/feature-column-reordering)
- [ Column Visibility ](https://laravel-datatables.com/docs/feature-column-visibility)
- [ Custom Filters ](https://laravel-datatables.com/docs/feature-custom-filters)
- [ Custom Controls ](https://laravel-datatables.com/docs/feature-custom-controls)
- [ Exporting ](https://laravel-datatables.com/docs/feature-exporting)
- [ Freeze Columns and Headers ](https://laravel-datatables.com/docs/feature-freeze-columns-and-headers)
- [ Pagination ](https://laravel-datatables.com/docs/feature-pagination)
- [ Responsive Mobile ](https://laravel-datatables.com/docs/feature-responsive-mobile)
- [ Row Grouping ](https://laravel-datatables.com/docs/feature-row-grouping)
- [ Row Selection ](https://laravel-datatables.com/docs/feature-row-selection)
- [ Sorting and Searching ](https://laravel-datatables.com/docs/sorting-and-searching)
- [ State Persistence ](https://laravel-datatables.com/docs/feature-state-persistence)
- [ Value Preparation ](https://laravel-datatables.com/docs/feature-value-preparation)

### Cell Renderer

- [ Action Buttons ](https://laravel-datatables.com/docs/renderer-action-buttons)
- [ Avatar ](https://laravel-datatables.com/docs/renderer-avatar)
- [ Checkmark ](https://laravel-datatables.com/docs/renderer-checkmark)
- [ Color Sample ](https://laravel-datatables.com/docs/renderer-color-sample)
- [ Email Link ](https://laravel-datatables.com/docs/renderer-email-to-link)
- [ External Link ](https://laravel-datatables.com/docs/renderer-external-link)
- [ Friendly Timestamp ](https://laravel-datatables.com/docs/renderer-friendly-timestamp)
- [ Image ](https://laravel-datatables.com/docs/renderer-image)
- [ Long Text ](https://laravel-datatables.com/docs/renderer-long-text)
- [ Phone Link ](https://laravel-datatables.com/docs/renderer-phone-link)
- [ Progress Bar ](https://laravel-datatables.com/docs/renderer-progress-bar)
- [ Status Badge ](https://laravel-datatables.com/docs/renderer-status-badge)
- [ URL Link ](https://laravel-datatables.com/docs/renderer-url-link)
- [ Wire Link ](https://laravel-datatables.com/docs/renderer-wire-link)

### Value Formatter

- [ Compact Number ](https://laravel-datatables.com/docs/formatter-compact-number)
- [ Currency ](https://laravel-datatables.com/docs/formatter-currency)
- [ Duration ](https://laravel-datatables.com/docs/formatter-duration)
- [ Friendly Filesize ](https://laravel-datatables.com/docs/formatter-friendly-filesize)
- [ Friendly Timestamp ](https://laravel-datatables.com/docs/formatter-friendly-timestamp)
- [ Locale Timestamp ](https://laravel-datatables.com/docs/formatter-locale-timestamp)
- [ Number ](https://laravel-datatables.com/docs/formatter-number)
- [ Percent ](https://laravel-datatables.com/docs/formatter-percent)

  State Persistence
=================

State persistence controls how search, sort, filters, visible columns, per-page selection, and optionally selected rows are restored between requests.

1. Enable Persistence Per Table
-------------------------------

Use Datatable properties for table-level behavior.

 Datatable properties PHP     `public bool $persistTableState = true;public bool $persistSelectedRows = true;` 

 ```
public bool $persistTableState = true;
public bool $persistSelectedRows = true;
```

2. Global Persister Configuration
---------------------------------

The package resolves StatePersisterInterface from config and the container.

 config/laravel-datatable.php PHP     `return [    'state_persister' => \MorrowIt\LaravelDatatable\State\SessionStatePersister::class,];` 

 ```
return [
    'state_persister' => \MorrowIt\LaravelDatatable\State\SessionStatePersister::class,
];
```

3. Hydration During Mount
-------------------------

The datatable boot sequence runs a state initialization step after the component has a stable table identifier.

 initializeState() bootstraps the table PHP     `public function mount(?string $tableId = null, string $direction = 'ltr'): void{    $this->direction = in_array($direction, ['ltr', 'rtl'], true) ? $direction : 'ltr';    $this->tableId = 'directionality-' . $this->direction;    $this->initializeState();}` 

 ```
public function mount(?string $tableId = null, string $direction = 'ltr'): void
{
    $this->direction = in_array($direction, ['ltr', 'rtl'], true) ? $direction : 'ltr';
    $this->tableId = 'directionality-' . $this->direction;

    $this->initializeState();
}
```

initializeState() is the place where the component loads persisted values, normalizes the current column order and visibility, and resets selected rows when persistence is disabled. It ensures the table starts in a valid state before the first render and keeps ordering rules consistent when session state is present.

This hook also handles the default state for tables that do not need persistence: it will still normalize column visibility and order according to the currently declared columns and freeze settings.

See the [Directionality demo](/demos/features-directionality?dir=rtl) for a practical example where direction is set in mount() and then initializeState() is invoked to hydrate the table state.

4. Custom Persister Implementation
----------------------------------

Create a persister class when state must be stored outside session.

 Custom persister PHP     `namespace App\Support\Datatable;use MorrowIt\LaravelDatatable\Contracts\StatePersisterInterface;class EloquentStatePersister implements StatePersisterInterface{    public function save(string $tableId, array $state): void    {        // Persist state.    }    public function load(string $tableId): array    {        return [];    }    public function clear(string $tableId): void    {        // Clear state.    }}` 

 ```
namespace App\Support\Datatable;

use MorrowIt\LaravelDatatable\Contracts\StatePersisterInterface;

class EloquentStatePersister implements StatePersisterInterface
{
    public function save(string $tableId, array $state): void
    {
        // Persist state.
    }

    public function load(string $tableId): array
    {
        return [];
    }

    public function clear(string $tableId): void
    {
        // Clear state.
    }
}
```

 Per-table override PHP     `use MorrowIt\LaravelDatatable\Contracts\StatePersisterInterface;protected string|StatePersisterInterface|null $statePersister = \App\Support\Datatable\EloquentStatePersister::class;` 

 ```
use MorrowIt\LaravelDatatable\Contracts\StatePersisterInterface;

protected string|StatePersisterInterface|null $statePersister = \App\Support\Datatable\EloquentStatePersister::class;
```

Use stable and unique table identifiers per context to avoid restoring one screen state into a different table.

If persisted selected rows are enabled, re-authorize IDs before bulk actions because permissions may change between sessions.

   © 2026 Copyright (C)  [ Morrow IT Consulting &amp; Services ](https://morrow-it.services)  

 [Terms of Service](https://laravel-datatables.com/legal/terms) [Privacy](https://laravel-datatables.com/legal/privacy) [Legal Disclosure](https://laravel-datatables.com/legal/disclosure)
