SearchPanes custom Order
SearchPanes custom Order

I am currently creating a Custom Search pane with Custom Options. I have it working but it is completely ignoring the Order value. I've created several on the same Datatable manually typing out an array, but in this instance I'm gathering the options from an ajax call before the datatables is loaded.
success: function (response) {
response.forEach(function(role) {
unverifiedOptions.push({
label: role.name,
value: function (rowData, rowIdx) {
return rowData["unverifiedRoles"] && rowData["unverifiedRoles"].includes(role.name);
},
order: role.order
});
});
}
Then in the search panes:
Again, this works, it filters the data as intended, but the order in the SearchPane lists the order in this order:
10-19 (in order) then lists 2-9 (in order).
I thought maybe it was doing a string sort, so I did a parseInt(role.order)
and it had no affect.
I'm a little confused.
Answers
I found this thread which has a test case trying to use
order
and its not working. Then I found this thread where Allan added theorder
capability. I updated the test case in the first thread to use the latest versions and it still didn't work.https://live.datatables.net/bamuvuno/2/edit
Looking at the searchPanes code Allan made the change in
SearchPane.prototype._getComparisonRows
. I also foundSearchPaneCascade.prototype._getComparisonRows
which doesn't have that change. The test case hadsearchPanes.cascadePanes
enabled so theorder
property was not used. Commenting out// cascadePanes: true,
allowsorder
to work.Do you have
searchPanes.cascadePanes
enabled?@allan might need to add support for
order
toSearchPaneCascade.prototype._getComparisonRows
. Also there is no documentation fororder
tosearchPanes.panes.options
andsearchPanes.panes.options
.Kevin
I do not have cascadePanes enabled. I think we found the same threads as this is in my code:
I am getting my data via Ajax.
Are you using the
ajax
option? I could be wrong but I don't believe this will affect the use theorder
option.It's hard to tell from your code but I assume you are using jQuery ajax() to fetch the options in your first code snippet. Use of
success
is not supported in theajax
option:I wonder if you need to move the Datatables initialization into the
success
function after building theunverifiedOptions
object. Since ajax is asynchronous that object might not be build when Datatables is initialized. However in the debugger you might be seeing the builtunverifiedOptions
object but not what Datatables used.It's hard to say what the problem might be with just a couple small code snippets. I would first start by outputting the
unverifiedOptions
to the console. Make a copy of it to assign directly in your application. Comment out the ajax request. Does it work with hard coded data?Can you post a link to a test case showing the issue so we can help debug?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Yeah I encountered those issues, I'm populating datatables data through ajax, but the variable I'm giving to the SearchPanes for options is created before initialization of datatables and not in the same call ajax call.
If its not working in your test case you updated, it ain't going to work in mine.
Sorry if my comments are confusing. This test case does work:
https://live.datatables.net/bamuvuno/2/edit
As I said commenting out
// cascadePanes: true,
allows it to work. You can seeLOWS
is listed last which is defined by theorder
. Otherwise it will be listed afterCRITICALS
.Ok, but Ajax is asynchronous. The best way to verify the `` is populated with what is expected is to use
console.log(JSON.stringify( unverifiedOptions ));
on the line before Datatables is initialized. What does this output show?Kevin
I made it synchronous to get around that issue. The breakpoint shown above is the JS debugger, where the variable is populated with an array of options at time of column creation in datatables.. here is my call:
Please note async: false,
This is my break point ON the line of creating datatables, the variable is populated. The options DO show in the drop down, just not ordered correctly.

I'll see if I can get a test case going with your example.
We have to be sure, since we can't see it, that the async nature of Ajax requests is not causing unexpected values
I built a test case based on your code. It needed some refactoring to work in the https://live.datatables.net/ environment. It has
ajax
loaded data and uses something similar to your above ajax request fetching the options.https://live.datatables.net/yelucufi/1/edit
The order is set by the
order
option.Maybe try a breakpoint in
dataTables.searchPanes.js
in the functionSearchPane.prototype._getComparisonRows
. Maybe place a breakpoint on thereturn rows;
at the end of the function. Interrogate theoptions
object. What do you find?Kevin
Hey it works in your example! I was just about to come back and mention that when I manually type out the values they DO work... but those are usually only a few options...
OKAY I see the issue.. check this out https://live.datatables.net/yelucufi/3/edit
Now look at the order.
Right, you mentioned sorting was string based instead of numeric. Sorry forgot about that. I'm not sure how the order is applied. @allan will need to take a look.
A workaround appears to be to set the
columns.type
tonum
for the SearchPanes column usingcolumns.searchPanes.dtOpts
. For example:https://live.datatables.net/yisomaci/1/edit
Kevin
Crazy work around, but it works. Thanks.