Page 1 of 1

[VUE 2] StateManager apply state does not apply the state

Posted: Tue Dec 06, 2022 11:32 am
by dev_man_44

I use 5.2 version of Grid. Trying to implement state save and after reload keep apply the saved state.
I checked this topic also but StateProvider.setup('local') is not working. https://bryntum.com/products/grid/examples/state/

My Vue 2 code implementation:

<bryntum-grid
        ref="grid"
        v-bind="gridConfig"
        :data="filteredItems"
        class="flex-1"
        @cellclick="cellClick"
        @selectionchange="selectionChange"
      />

data have variables: gridInstance: null, gridStateId: 'grid.state-id'.

mounted() {
    this.gridInstance = this.$refs.grid.instance
    if (this.gridInstance) {
      const savedState = localStorage.getItem(this.gridStateId)
      if (savedState && this.gridInstance) {
        const parsedState = JSON.parse(savedState)
        this.gridInstance.applyState(parsedState)
      }
    }
  },
methods: {
    saveState() {
      localStorage.setItem(this.gridStateId, JSON.stringify(this.gridInstance.state))
    },
    resetState() {
      localStorage.removeItem(this.gridStateId)
    },
  }

I call saveState method on column filtering and I checked the localStorage and the actual state saved there. And tested that state got from localStorage on mounted hook and passed to applyState function correctly. Attached image about localStorage.


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Tue Dec 06, 2022 2:55 pm
by alex.l

The code you posted looks correct. Could you please attach a runnable app, the problem might be in something different. Maybe the grid updated twice?


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Wed Dec 07, 2022 10:56 am
by dev_man_44

I created a demo project on my git repo:
https://github.com/Abdulla1995/bryntum-vue2-state
I call saveState function but also added some comments there. Please answer it also why state not updating on this method?


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Fri Dec 09, 2022 8:34 am
by alex.l

I tried your demo, all works fine to me. Please see video attached.
What's the actual problem?


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Sat Dec 10, 2022 11:31 am
by dev_man_44

I checked your video but I need the deleted (hidden) column not appear after refresh. Can you please try it and see the result ?


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Wed Dec 14, 2022 3:35 pm
by alex.l

Please see video attached. I still don't see any problems.


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Thu Dec 15, 2022 11:45 am
by dev_man_44

I watched your video and see that it works. I tested it now it works. I really curious about what was wrong :/ . For the last video try to hide Phone filed and save then reload. Seems it does not get saved. Then added field: '' into that phone column in the colums section and it also started working and saved if hidden. May be this causes the bug.


Re: [VUE 2] StateManager apply state does not apply the state

Posted: Sun Dec 18, 2022 4:01 pm
by alex.l

Then added field: '' into that phone column in the colums section

Sorry, I don't follow. Could you please re-phrase this part?