column().search() does not seem to work on a specific case
column().search() does not seem to work on a specific case
this is my datatable implementation, that works fine nothing wrong here
var dTable = $('#ajaxresults').DataTable({
"order": [[1, "desc" ]],
"sPaginationType": "full_numbers",
"ajax": "/admin/users/getdata/",
createdRow: function(row, data, index) {
if(data[6]=="Special Award") {
$(row).addClass('special');
}
}
});
but i've added a sort dropdown that uses the column().search() helpers, like this
$('#sortby').change(function() {
var srcVal = $(this).val();
if(srcVal=="") {
dTable.column(0).search("").draw();
} else {
if(srcVal == "Special Award") {
dTable.column(6).search("Special Award").draw();
} else {
dTable.column(0).search(srcVal).draw();
}
}
});
now if i select anything except "Special Award" everything works fine, but if i select Special Award it does not work, but the Special Award wording is on column 6 as can be seen below on the data that comes from server
["Not Submitted", "2017-03-27", "John Doe", "johndoe@google.com", "123-123-1234", "<a href="/admin/users/edit/id/4404">View</a>", "Special Award"],
["Approved", "2017-03-27", "Marry Jane", "marryjane@google.com", "123-123-1234", "<a href="/admin/users/edit/id/4405">View</a>", ""]
any idea why column(0) works just fine but column(6) does not ?
Kind regards,
Claudiu
Answers
Looks like your search function should work. Have you tried validating that
srcVal
does equalSpecial Award
when you select that option?Maybe a console log message under
if(srcVal == "Special Award")
to see if the condition is true. Maybe another undervar srcVal = $(this).val();
to display the value ofsrcVal
.Kevin
oh yes, that's one of the first thing i looked at and yes it enters in that if statement and my list will draw empty although there are rows that on 6 column has "Special Award" in it ...
Can you provide a test case?
I tried your code snippet with different data and the logic of it works.
Kevin
hmm can u post your test here so i can check it out ?
how can i provide a test case ?
Kind regards,
Claudiu
How to post a test case:
https://datatables.net/manual/tech-notes/10
All I did was take your if statement, modified it a bit to fit my data and tried it just to test the logic. Build the test case using a sample of your data and your config with
createdRow
, etc.Kevin