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

w2ui 2.0 grid - uninteded run events onStateRestore, onStateSave after new grid instantiate #2453

Closed jankrnavek closed 10 months ago

jankrnavek commented 10 months ago

version: Vue 3, w2ui 2.0 grid

I am trying to get the grid working in my Vue 3 app with remote data fetching from the server. The user can restore or save the column state to the server as well. (on the columns menu), I use events onStateRestore and onStateSave for it. But I have problems with these two events because they run automatically once the new grid is instantiated. (without any user action). I don't want it. What can I do about it?

Code snippet with imported parts.

...
<script setup>
import {w2grid, w2ui} from 'https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.es6.min.js'

const gridConf = {
    name: 'grid',
    box: '#grid',
    url: recordsUrl,
    method: 'GET', 
    style: 'height: 100%;',
    records: [],
}

onMounted(async () => {
    console.log('mounted')

    gridConf['columns'] = columnsDefinitonFromRemoteStore()

    gridConf['onStateSave'] = function (event) {
        event.onComplete = function () {
            console.log('onStateSave onComplete')
        }
    }

    gridConf['onStateRestore'] = function (event) {
        event.onComplete = function () {
            console.log('onStateRestore onComplete')
        }
    }

    new w2grid(gridConf)
})

onBeforeUnmount(() => {
    console.log('unmounted')

    if (typeof w2ui.grid !== 'undefined') {
        w2ui.grid.destroy()
    }
})
</script>

<template>
    <div id="grid"></div>
</template>

...

To make it clear. I want user to be able to manually via onColumnContextMenu save and fetch state of columns into server. (I don't want to use localc storage). Using events onStateRestore/onStateSave to fetch/post the context of grid["columns"] property to the server. Therefore I don't want these events to be automatically triggered when the new grid is created. Is it possible to disable or bypass this behaviour?

An the second question. Can I modify/add items into onColumnContextMenu ?

Thank you.

jankrnavek commented 10 months ago

Finnaly I used event onToolbar for implementing the code for save/restore column settings to the remote server.