Add Column Filtering on specific columns
Add Column Filtering on specific columns
careywalker
Posts: 4Questions: 0Answers: 0
I have the example for DataTables Individual Column Filtering working. I don't want to filter on all columns in the DataTable, I only want to filter on specific columns in the DataTable. Does anyone know how to do this?
This discussion has been closed.
Replies
Allan
--the code below is from the Example: http://datatables.net/release-datatables/examples/api/multi_filter_select.html
$("tfoot th").each( function ( i ) {
this.innerHTML = fnCreateSelect( oTable.fnGetColumnData(i) );
$('select', this).change( function () {
oTable.fnFilter( $(this).val(), i );
} );
} );
This will add a filtering select list to each column. What I am asking is how to add the filtering select list to specific columns. My data table has 10 columns and I only want to add the filter select lists to 4 of those columns.
I added an ID value to each of the elements as in:
and then I use the id value to add the filtering select lists to the required columns:
$("thead td").each(function (i) {
if (this.id == 3 || this.id == 4 || this.id == 5 || this.id == 6 || this.id == 8 || this.id == 9 || this.id == 11) {
this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
$('select', this).change(function () {
oTable.fnFilter($(this).val(), i);
});
}
});
I would be happy to know if there is a better way of doing this, maybe using the index value of "this" to decide whether or not to add a filtering select list to a column.
$("thead td").each(function (i) {
if (i == 2 || i == 3 || i == 4 || i == 5 || i == 7 || i == 8 || i == 10) {
this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i));
$('select', this).change(function () {
oTable.fnFilter($(this).val(), i);
});
}
});