Nightly build does not store "special" selected filters via stateSaveCallback

Nightly build does not store "special" selected filters via stateSaveCallback

pgerundtpgerundt Posts: 90Questions: 13Answers: 2

There is a bug in the nightly build of searchPanes - it works with the previous releases. Once again, I cannot provide a test case because there is no working ajax endpoint for retreiving data unter live.datatables.net.

Imagine having a simple table with one column ("location"), displaying the human-readable location name in the table and providing a searchPane with human-readable label but the database id as value.

Your ajax call would return something like:

{
  draw: 1,
  ...
  data: [
    {
      location: 'Munich'
    },
  ...
  searchPanes: {
    options: {
      location: [
        {
          label: 'Munich',
          value: "42",             <---- here is the problem
          count: 1,
          total: 1
        }
        ...
    }
  }
}

When selecting this filter the stateSaveCallback is triggered and data contains the selected filter. Perfect.

But if you reload the page, stateSaveCallback: function(settings, data) is triggered once again but the data does not contain the selected filter anymore:

{
  searchPanes: {
    panes: [
      {
        ...
        selected: []             <---- here is the bug
      }
    ]
  }
}

This only occurs if your searchPanes option (see above) has a different value from the label. If you set the value to "Munich", everything works fine.

Even when storing the state in the dom (without stateSaveCallback), this does not work.

Replies

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

    That's odd, we've not seen that before. This example shows a working Ajax end-point - would you be able to use that to knock out an example we could debug, please.

    Colin

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Dear @colin,

    I checked your example, but it doesn't show the bug and cannot be changed to show it.

    We'll need an Ajax call additionally returning the search panes data with at least one filtering item with value different from its text.

    I'll try to modify the example to use an Ajax endpoint from one of our servers.

    pgerundt

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Dear @colin,

    took me some time, but I got a running example:
    http://live.datatables.net/ruhuguwu/91/edit

    Please note that the filter on "Name" gets stored correctly, but the filter on "Location" is lost when clicking on "Run with JS" or reloading the page.

    This is caused by the ajax response from http://showroom.efficient.it/ajax.php containing human-readable label but database ids in value.

    For debugging you could also use the example
    https://datatables.net/extensions/searchpanes/examples/initialisation/ajaxOptions.html
    and modify the options.json file.

    I traced the bug down to
    SearchPanes.prototype._makeSelections():
    the variable selectList contains the correct value (the database id 1 for "Dunfermline" or 2 for "Munich"), but it is compared with the label ("Dunfermline" or "Munich"):
    if (selection.rows.includes(pane.s.dtPane.cell(i, 0).data()))

    I know this is a tricky one and maybe hard to understand, but this used to work before and it's pretty useful to have different value from label for the filter items to query the database and return the correct rows via Ajax.

    Hope that helps and kind regards,

    pgerundt

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

    Thanks for looking at that. Sandy is back in the office towards the end of next week, and he'll take a nose at it then and report back,

    Colin

  • sandysandy Posts: 913Questions: 0Answers: 236

    Hi @pgerundt ,

    Thanks for pointing this out. That should be the issue fixed now as you can see at this example. This will be available in the next SearchPanes release which we hope will be in the next few weeks. Until then you can access the fix from the nightly builds.

    Thanks,
    Sandy

  • pgerundtpgerundt Posts: 90Questions: 13Answers: 2

    Hi @sandy,

    I just checked the nightly build and everything seems to be fine now. Thank you very much.

    pgerundt

Sign In or Register to comment.