Column search with array - undocumented change in behaviour upgrading from 1.12.1 to 2.3.8
Column search with array - undocumented change in behaviour upgrading from 1.12.1 to 2.3.8
Previously (1.12) if an array was passed to column search this was changed to a delimited string. Now this change is not being performed.
console.log($('#Status').val()); //['Prospect', 'Active']
api.column(3).search($('#Status').val(), false, false, false);
1.12
columns[3][search][value] Prospect,Active
2.3.8
columns[3][search][value][] Prospect
columns[3][search][value][] Active
Is this change intentional?
Should find and add in the all places in code .join to turn arrays into strings?
Should I instead change the server side model binding to handle both string and array for same variable?
Or is this breaking change unintentional and be reverted?
If it's intentional, the documentation on these pages should be updated
https://datatables.net/manual/server-side
https://datatables.net/upgrade/2
Thanks!
Replies
Not really intentional, but also passing an array into
column().search()is not something that was ever documented (and therefore not supported). Indeed, checking the current docs it still isn't mentioned, so what happens is undefined behaviour.In the newer versions of DataTables, it is possible to pass in more than just strings (regex and functions for example), which is why it will no longer just
toStrings everything.My suggestion would be to add
.join(',')to make it explicit that a string is being passed in if that is what you are expecting at the server side, although updating the server's code to expect the array might be preferable.I'll have a think about documenting the array behaviour. The new one seems right of the top of my head. Sorry that it means you will need to make a code change.
Allan