vitmalina / w2ui

UI widgets for modern apps. Data table, forms, toolbars, sidebar, tabs, tooltips, popups. All under 120kb (gzipped).
http://w2ui.com
MIT License
2.64k stars 730 forks source link

w2Grid 2.0+ localStorage overriding new constructor #2427

Open Madrok opened 1 year ago

Madrok commented 1 year ago

localStorage state overrides new construction

current behavior If you create a grid with no toolbar, render it, then change the source code to add a toolbar, the grid will still show with no toolbar. As long as the name is not changed, the new options are not honoured.

This is due to the fact that the localStorage for that grid name has already been saved. and there's no direct save of the current state in the constructor before render() is called

stateRestore() is called with empty params from render() right at the end of the constructor

constructor()->render()-> line 5576: stateSave(true) [return data only, nothing saved to localStorage] line 5577: stateRestore() The error shows up in stateRestore(newState) because newState is undefined line 8401: if (!newState) { newState = this.cache('state') } after which, the state of the original named instance is fetched from localStorage

I think simply a call to force save the state to local storage at the end of the constructor is all that's needed to fix the error. The same error may be in other components using saved state, but I only just created a grid so far.