Is there an option in here where we can do an OR filter by column?

Is there an option in here where we can do an OR filter by column?

dataphpmysqldataphpmysql Posts: 65Questions: 17Answers: 0

Hello. I'm looking to see if there's an option here in dataTables that we can do an OR filter by column?

So for example, lets say I have a table with 3 rows and 3 columns:
Column1 - Column2 - Column3
1 2 3
a b c
4 5 6

And I have:
Search input for Column 1 = a
Search input for Column 2 = 5
Search input for Column 3 = 3

This would in fact return all 3 columns instead of none.

Is there something like this in dataTables? Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    You would use a search plugin for this. See if this thread helps:
    https://datatables.net/forums/discussion/comment/153553/#Comment_153553

    Kevin

  • dataphpmysqldataphpmysql Posts: 65Questions: 17Answers: 0

    Thanks for the help!

    The last example: http://live.datatables.net/mucevape/1/edit is close to what I'm looking for. Only two things I would like to change. 1. Can I change the <select> into a general input search where user types in the field? and 2. Can I change the position of that search field outside of the table anywhere on the page? Thanks.

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    Yes to both. Its just an input. You can use what you want and place them anywhere you want. Your event handler for the inputs will simply need to use draw() and in the plugin you fetch the input values and process them as needed.

    Kevin

  • dataphpmysqldataphpmysql Posts: 65Questions: 17Answers: 0

    I managed to change the position (although it changed both instead of one) as well as changing from 'select' into 'input' however the data is not being filtered on the table. Do you know what could be wrong? Here is the edit: http://live.datatables.net/mucevape/39/edit

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    If you want text inputs then you wouldn't use any of the code inside the initComplete function. That is for select inputs. You will need to create the text inputs and create a different event handler. Here is an example:
    http://live.datatables.net/lecixuca/3/edit

    Kevin

  • dataphpmysqldataphpmysql Posts: 65Questions: 17Answers: 0

    I was hoping for the data on the table to be updated as I type (like the general search). Also, it looks like it only works if it matches 100%. So I'm taking from this that there's no plug in or easy way of doing this? Thanks for the help though!

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    I showed one simple example. The input you use and the code you use in the plugin is not restricted by Datatables. You can implement the behavior you want.

    Instead of invoking the event on a change you can use keyup which would behave more like the default search. Within the plugin you can use a regex match instead of simply using ===.

    Kevin

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769
    Answer ✓

    Thinking about it for a bit I realized that doing an OR search across multiple columns might not be that straight forward. You need to be able to properly handle the case of one inout being blank while the other contains input. Here is the example updated with regex search and keyup event:
    http://live.datatables.net/hocoyuke/4/edit

    The complexity will increase with more columns.

    HTH,
    Kevin

  • dataphpmysqldataphpmysql Posts: 65Questions: 17Answers: 0

    Awesome! that's definitely what I was looking for. Thanks!

This discussion has been closed.