Filtering Datatable columns using OR logic

Filtering Datatable columns using OR logic

SKRSKR Posts: 13Questions: 0Answers: 0
edited September 2012 in DataTables 1.8
Hi,

I am using DataTables 1.8.1 .I have a few jquery datatables in my application. Currently columns are filtered using AND logic i.e.first column is filtered using some criteria and then the second column filter is applied on the resultset obtained by filtering first column and so on.
For this purpose every time you apply a filter criteria, the _fnFilterColumn function present in jquery.dataTables.js file is invoked.
In this function the elements which do not match the filter criteria are spliced from oSettings.aiDisplay.
This is the array containing row data.The second column uses this filtered array for further processing.

This is not what I want. I am required to use AND or OR logic for filtering i.e. Suppose if I have an array of 50 elements. I apply a filter criteria on the first column which reduces my array to just 25 elements. Then while filtering second column, i need to filter on the original array containing 50 elements and not the one containing 25 elements. How do I achieve this without affecting other datatables in my application? Will I have to make changes t0 jquery.dataTables.js?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    To get OR filtering in DataTables you can use two methods:

    1. Regex - if the OR is on a single column
    2. Custom filters ( http://datatables.net/development/filtering ) - effectively bypassing the built in filtering, if you need to OR over multiple columns.

    There isn't currently a good built in way to do OR over multiple columns without a custom filter. This is something that I will add to the future feature list.

    Allan
  • jorwanjorwan Posts: 2Questions: 1Answers: 0
    Yeah, i would love that a lot !! xD :)
  • pranabpranab Posts: 2Questions: 0Answers: 0
    I am trying to achieve 'OR over multiple columns'. I have Firstname, Lastname and phone columns. I want to do a search filter like this ;
    (Firstname AND Lastname ) OR (phone)
    The default search does (Firstname AND LAstname AND phone) .
    Not sure how i can do this with custom filters. Can anyone help me with this ?
This discussion has been closed.