Custom filtering (columns)

Custom filtering (columns)

Jon74Jon74 Posts: 2Questions: 0Answers: 0
edited October 2013 in General
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

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2013
    The layouts are specified in a string in sDom. If you don't override the default, you get a standard setup that includes number of rows, global filter, table, pagination, like in the "zero config" example at http://datatables.net/release-datatables/examples/basic_init/zero_config.html

    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/
  • Jon74Jon74 Posts: 2Questions: 0Answers: 0
    edited October 2013
    Thanks a lot fbas, very clear and helpful

    Just one thing is still not clear: for multi-filtering I need to have global filter active?
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    No. the multi-filters and global filter are distinct. You can use them in tandem (i.e. something has to match the global filter and a column filter) or just use one.

    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]
This discussion has been closed.