SearchPanes and option stateSave: true, refresh data issue

SearchPanes and option stateSave: true, refresh data issue

martinxmuellermartinxmueller Posts: 8Questions: 1Answers: 0

A datatable reloads the data in a period of x seconds.
In order to refresh the view, i call $('#mytable-id').DataTable().clear().rows.add(<new data>).draw();
After that i call $('#mytable-id').DataTable().searchPanes.rebuildPane();
If i do so, searchPanes is rebuild with the initial state of the DataTable. But the initial state is not the latest state. That means the restored selections in searchPanes is not what the user had before data refresh is started.
I think, the reason is in function SearchPane.prototype._buildPane().
In the line 'var loadedFilter = table.state.loaded();' the initial state is reloaded. For me, it would be better to load the current state: 'var loadedFilter = table.state();'
So i changed the line in SearchPane.prototype._buildPane(). But the result was not what i expected.
After further debugging i see in function 'SearchPanes.prototype.rebuild' the call of 'this.clearSelections()' causes a reset of the 'current state'. The selections of searchPanes are cleared in the 'current state' of DataTable. Thus my change in ' SearchPane.prototype._buildPane()' forces a reset to 'empty selections'.
My temporarily solution for this problem is saving the 'current state' in function 'SearchPanes.prototype.rebuild':
var stateBeforeClear = this.s.dt.state(); I do this before clearSelections() is called. I use the saved state in 'SearchPane.prototype._buildPane()' and get the expected behaviour in case of rebuild the searchPanes after data refresh.

Replies

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    I suspect this problem has been resolved in an unreleased version of SearchPanes. You can find the nightly releases here, can you give that a try, please.

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • martinxmuellermartinxmueller Posts: 8Questions: 1Answers: 0

    I tested with nightly build from 2020-04-18.
    My described problem, init state after call of rebuildPane(), is solved now.
    Unfortunately, there is another issue in the nightly file: the pane-specific buttons don't work after rebuildPane(). The ClearAll button works.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    Thanks for that, I've reproduced that here. I've raised it internally (DD-1407 for my reference) and we'll report back here when there's an update.

    Cheers,

    Colin

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @martinxmueller,

    I've fixed the issue above and you can see it working in this version of your example. The code will be available in the nightly builds as colin mentioned above.

    Thanks,
    Sandy

  • martinxmuellermartinxmueller Posts: 8Questions: 1Answers: 0

    Hi,

    I tested with nightly file from 2020-04-21.
    Now, the pane-specific buttons work after call of rebuildPane().
    But the state management does not work in the new version. I have DataTables option stateSave: true. If i clear my search pane selection, after rebuildPane() the 'old' selection is restored. It doesn't matter which clear button i use.
    It seems, a deselect of a item in a search pane is not registered in the DataTables state.

    Cheers,

    Martin

  • martinxmuellermartinxmueller Posts: 8Questions: 1Answers: 0

    Hi,

    i can't reproduce the problem with state management that i described in the last comment!
    Now, it works like a charm.

    Cheers,

    Martin

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    It's always good when the pixies fix the bugs... :)

    Colin

  • martinxmuellermartinxmueller Posts: 8Questions: 1Answers: 0

    Hi,

    i'm sorry, but i see that the parameter 'maintainSelection' of function SearchPanes.prototype.rebuild = function (targetIdx, maintainSelection) is never used. Something wrong?

  • martinxmuellermartinxmueller Posts: 8Questions: 1Answers: 0

    Unfortunately, i still have a problem when i call 'datables.searchPanes.rebuildPane(void 0, true)'. Instead of the latest state, the initial state is restored.
    I assume the problem is in 'SearchPane.prototype._buildPane'. In this function are the lines
    // If the listeners have not been set yet then using the latest state may result in funny errors
    if (this.s.listSet) {
    loadedFilter = table.state();
    }

    Before _buildPane is called in function 'SearchPane.prototype.rebuildPane', the function 'SearchPane.prototype.destroy' is called. In destroy the variable this.s.listSet is set to 'false'. Therefore in _buildPane the latest saved state (table.state()) is never used.

    Cheers,

    Martin

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @martinxmueller ,

    Yes something not quite right here, I'll take a look into it for you. I've filed an issue internally (DD-1416 for reference) and will report back soon.

    Thanks,
    Sandy

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @martinxmueller ,

    I've added the functionality back in. It must have got lost somewhere, but it is back now and behaviour is as before. Again as mentioned above, this will be in the nightly builds until the next release.

    Thanks,

    Sandy

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    You can find the nightly releases here, and we're planning on making new releases in the next week.

    Colin

This discussion has been closed.