javascript not working in searchPanel options
javascript not working in searchPanel options
jiayin_guo
Posts: 2Questions: 1Answers: 0
Hi all,
my script is something like:
columnDefs: [
{
searchPanes: {
options: [
{
label: 'Under 5',
value: function(rowData, rowIdx) {
return rowData[4] <= 5;
}
},
{
label: '5 to 100',
value: function(rowData, rowIdx) {
return rowData[4] > 5 && rowData[4] <= 100;
}
}
]
},
targets: [4]
},
]
The two labels have been shown successfully, but it seems the function is not working: no result is found by the filter while I'm 100% sure the 4th column of my data contains a lot of values from 0-100.
Answers
This example works. Without seeing your data and the problem its hard to say what might be wrong. I would start by doing some debugging of the functions. Maybe a breakpoint on line 7 or 13 to see what rowData[4] is. Or you could use console.log statements.
If you still need help then please provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
rowData[4]
andtargets: [4]
are actually the 5th column in the table. The index starts from0
. Maybe thats the problem.Kevin
I am using ajax API to fetch the data to the table, will this make the function any different?
I saw some documentation about using this.row(), but I don't know what that is
No, the data source doesn't matter. Take an example of the XHR response and use it to create a test case using Javascript data, like this example.
Line 18 and 24 in the example I linked to uses
this.row()
. This uses therow()
API to get the row using therowIdx
parameter. This is the row index.What did you find when debugging the function as I suggested?
At a minimum, post your full Datatables init code and a screenshot of the web page showing the table and Search Panes. Better is a test case so we can see your data.
Kevin