Author Topic: Default state  (Read 112 times)

queensgambit9

  • Pro Ultimate
  • Sr. Member
  • *
  • Posts: 350
    • View Profile
Default state
« on: August 27, 2025, 05:55:03 pm »
Would it be possible to have a button in the toolbar to set a selected state as "default" (to be loaded on page load)?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6423
    • View Profile
Re: Default state
« Reply #1 on: August 27, 2025, 08:42:36 pm »
Yes, it’s possible to implement a “Set as Default” button in the toolbar using the saveState and loadState APIs. Here’s the approach:

Save the selected state as a string
When the user clicks your “Set as Default” button, call saveState and save the returned string somewhere persistent—like local storage or your database. For example:

Code: [Select]
const defaultState = grid.saveState({ stringify: true });
localStorage.setItem('myGridDefaultState', defaultState);

Load this default state on page load
On page load, retrieve the saved state string and pass it to loadState:

Code: [Select]
const savedState = localStorage.getItem('myGridDefaultState');
if (savedState) {
    grid.loadState({ state: savedState, refresh: true });
}