Custom filtering (columns)
Custom filtering (columns)
Hi all,
I am new to this forum and to datatables.
I have a simple datatable and my need is NOT to have global search filtering, but only for individual columns (2 out of 5 of my table).
I tried to search and apply the examples mentioned here: http://datatables.net/examples/api/multi_filter.html
but I faced that without global filtering ("bFilter:false" setting) neither the column filters are working, is this correct? if yes is it mandatory?
Further more the columns I need to do the filtering are only two out of 5 (the first and the third), but if I don't specify an input field for the second column, for the third one the filtering does not work.
Again, is it possible to customize the layout of the main components, i.e. move the dataTables_length Div or the dataTables_info?
Any help is very appreciated.
Thanks
Jon
I am new to this forum and to datatables.
I have a simple datatable and my need is NOT to have global search filtering, but only for individual columns (2 out of 5 of my table).
I tried to search and apply the examples mentioned here: http://datatables.net/examples/api/multi_filter.html
but I faced that without global filtering ("bFilter:false" setting) neither the column filters are working, is this correct? if yes is it mandatory?
Further more the columns I need to do the filtering are only two out of 5 (the first and the third), but if I don't specify an input field for the second column, for the third one the filtering does not work.
Again, is it possible to customize the layout of the main components, i.e. move the dataTables_length Div or the dataTables_info?
Any help is very appreciated.
Thanks
Jon
This discussion has been closed.
Replies
The "DOM positioning" example shows use of the sDom: http://datatables.net/release-datatables/examples/basic_init/dom.html
Or see http://datatables.net/ref#sDom
Now back to multi-filtering. The reason your code does not work as expected, if you use this code with some inputs removed, is that this code is using the DOM position of the input textboxes in the footer to get a column number - see the ".index(this)"
[code]
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
[/code]
If your approach skips over some columns, this will have to change. You can solve this in a variety of ways, such as including a column number in a data attribute in that input tag, for example. http://api.jquery.com/data/
Just one thing is still not clear: for multi-filtering I need to have global filter active?
Ultimately, I think they both use the same base as fnFilter (if you don't specify a column in param 2, it checks all searchable fields)
http://datatables.net/ref#fnFilter
[the default zero-config init places a filter textbox for you, but you could write your own using fnFilter and place it anywhere on your page, outside of the datatable div, for example. the multi-filters use the fnFilter function, but specify which column the filter applies to]