How to filter table with greater than or lesser than columns?

How to filter table with greater than or lesser than columns?

edwinlohedwinloh Posts: 10Questions: 0Answers: 0
edited February 2014 in General
Hi,

I'm googling how to filter a datatable with "greater than" or "lesser than" with fnFilter.

And I found this post this http://datatables.net/forums/discussion/537/fnfilter/p1.

Which lead me to http://datatables.net/examples/plug-ins/range_filtering.html, but while reading "$.fn.dataTableExt.afnFiltering.push" code. I don't quite see how to state which table to apply this custom filtering with.

How can I specify which specific tables for the custom filtering?

Thanks!

Best Regards,
Edwin Loh

Replies

  • daniel_rdaniel_r Posts: 460Questions: 4Answers: 67
    You can take a look at my yadcf plugin source code for that

    Here an example of multiple tables with several kinds of filters (including from to , I call it filter_type: "range_number")

    http://yadcf-showcase.appspot.com/multiple_tables.html

    https://github.com/vedmack/yadcf/
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited February 2014
    > How can I specify which specific tables for the custom filtering?

    Unfortunately this is a limitation of the custom filtering functions. By default they are applied globally.

    However, it is actually relatively simple to check for an individual table:

    [code]
    $.fn.dataTableExt.afnFiltering.push(
    function( settings, data, dataIndex ) {
    if ( settings.nTable.id !== 'myId' ) {
    return true;
    }

    // filtering logic
    }
    );
    [/code]

    Basically, use the `settings.nTable.id` option to limit the search logic to a specific column.

    Or checkout Daniel's YADCF plug-in which nicely handles all this stuff internally :-)

    Allan
  • edwinlohedwinloh Posts: 10Questions: 0Answers: 0
    Hi Allan,

    Will the $.fn.dataTableExt.afnFiltering.push method work for server side data too?

    I tried to use $.fn.dataTableExt.afnFiltering.push and it works for non server side data.
    But when I tried to use it with server side data. It does not work.

    Thanks!

    Best Regards,
    Edwin Loh
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > Will the $.fn.dataTableExt.afnFiltering.push method work for server side data too?

    No. In server-side processing mode, all the processing is done on the server-side, including filtering. If you want to add more filtering prions when using server-side processing, you need to do it at the server :-).

    Allan
  • edwinlohedwinloh Posts: 10Questions: 0Answers: 0
    Hi Allan!

    Sigh! It "hit" me when I was debugging further after I messaged you. Wasted 2 days!

    But, my own sandbox, I got basic filtering using server-side with fnServerParams and calling fnDraw when I want to apply the filter.

    Is the the correct way?

    Thanks,
    Edwin Loh
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Perfect - yes, that is exactly the way to do it :-)

    Allan
This discussion has been closed.