How to Exclude a Column From Filtering
How to Exclude a Column From Filtering
Hi,
I have a DataTable with seven column and I have added column filtering to the table footer as per the example on this site. The problem is that it only makes sense to be able to filter the table on the first four columns and to not present the option for the remaining three. I have managed to exclude the final three columns from both sorting and searching, but the drop-down select list for filtering still appears in the footer. How can I prevent this please?
My code defining the DataTable is currently as follows:
$('#event_table').DataTable( {
"order": [[ 1, "asc" ]],
columns: [
{ data: "event", className: "editable", editField:'event'},
{ data: "date", className: "editable", editField:'date'},
{ data: "time", className: "editable", editField:'time'},
{ data: "venue", className: "editable", editField:'venue'},
{data:"total","bSearchable": false, "bSortable": false},
{data:"allocated","bSearchable": false, "bSortable": false},
{data:"paid","bSearchable": false, "bSortable": false}
]
,
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
myMule = val;
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
});
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
});
Many thanks
This question has an accepted answers - jump to answer
Answers
this.api().columns(".editable").every(...
Just use a selector in your columns call
https://datatables.net/reference/api/columns()
I've not tested it, if it doesn't work make an example on http://live.datatables.net
Works a treat, thank you!