Filter table in Editor instance
Filter table in Editor instance
New to DataTables. Trying to get a simple column filter to work. Example code in the API .filter() explanation does not filter my table. Code developed using older DataTables terminology (commented out in code) that I found through internet search does filter it. What am I missing with the .filter()?
var table = $('#1728ReportEdit').DataTable( {
dom: 'Bfrtip',
ajax: "php/table.1728ReportEdit.php",
columns: [
{
"data": "cnum"
},
{
"data": "progcategory"
},
{
"data": "purposeactivity"
},
{
"data": "projecttitle"
},
{
"data": "moneyraised"
},
{
"data": "hourscount"
},
{
"data": "date"
},
],
buttons: [
{ extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
},
{ extend: 'create', editor: editor },
{ extend: 'edit', editor: editor },
{ extend: 'remove', editor: editor }
]
}
);
// var filtercnum = '8285',
// filterIndex = 0;
//
//$.fn.dataTableExt.afnFiltering.push(
// function( oSettings, aData, iDataIndex ) {
// return aData[filterIndex].indexOf(filtercnum)>-1;
// }
//);
var filteredData = table
.column(0)
.data()
.filter( function ( value, index ) {
return value = 8285 ? true : false;
} );
This question has an accepted answers - jump to answer
Answers
It won't. As the
filter()
documentation notes:Using a search function like that which you have commented out (although that is using the old interface - this is the new) would be the correct way to do a condition such as
>
For a simple
==
condition you could usesearch()
.Note that in your code
value = 8285
will not do what you expect (even iffilter()
itself is not doing what you expected)! I think you meanvalue == 8285
for a comparison operator.Allan