Nightly build does not store "special" selected filters via stateSaveCallback
Nightly build does not store "special" selected filters via stateSaveCallback
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
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
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 itstext
.I'll try to modify the example to use an Ajax endpoint from one of our servers.
pgerundt
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 invalue
.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
fromlabel
for the filter items to query the database and return the correct rows via Ajax.Hope that helps and kind regards,
pgerundt
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
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
Hi @sandy,
I just checked the nightly build and everything seems to be fine now. Thank you very much.
pgerundt