Filter function with conditions for multiple columns

Filter function with conditions for multiple columns

GoaulGoaul Posts: 2Questions: 1Answers: 0
edited November 2021 in Free community support

Filter function with conditions for multiple columns
For example, there are 3 columns:
cityName, visitedTimes, canceledVisitTimes
London, 2, 0
Berlin, 0, 3

Filtering conditions in multiple columns, like:
filter=if "visitedTimes" >0 and "canceledVisitTimes" = 0
filter result=London

What would be a suggested way to filter this by using single button?
Button would be implemented like here: button example.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    if "visitedTimes" >0

    For filters like this you will need to create a search plugin similar to this range filter example.

    Kevin

  • GoaulGoaul Posts: 2Questions: 1Answers: 0
    edited November 2021

    That is for one column, no? Is needed to do that with 1 action (button).

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    The SearchBuilder would give you more flexibility.
    https://datatables.net/extensions/searchbuilder/

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765
    Answer ✓

    That is for one column, no?

    The search plugin has access to all the row data. You can do comparisons of one or more columns.

    Is needed to do that with 1 action (button).

    If your search works with column().search() then you can use column().search() instead of the plugin. You can use a combination of both. You can search multiple columns with column().search() then when the draw() is executed the search plugin will run for the "range" type search.

      function filterColumn( value, value1 ) {
        table.column(3).search( value1 );
        table.column(2).search( value ).draw();
      }
    

    You can see this in the Range search example. Perform a range search then use the global search for additional filtering.

    Kevin

Sign In or Register to comment.