Search specific column in global search field
Search specific column in global search field
Hello,
i want to have only one search field but the user should be able to search in a specific column.
For example i have a table with 4 columns:
id; name; lastname; city
1; Peter; Berlin; New York
2; Frank; Jakob; Berlin
3; Peter; Trump; Berlin
If i search now for "berlin" i get all 3 rows.
And i want that the user can for example search in column city like this "[city:berlin]"
Now the results should be row 2 & 3.
OR "[city:berlin] trump" give row 3 only.
So in [] search column and "trump" like normal global search.
Has anyone an idea how to realise that?
BR
This question has an accepted answers - jump to answer
Answers
Have you looked at individual column searching?
https://datatables.net/examples/api/multi_filter.html
Sure, but this has one search field for each column i want to have only one field.
BR
AFAIK, there's nothing like this built in.
Your best bet is to create your own search input field and bind a function to the keyup event that will evaluate the input and use
columns.search()
to search by a specific column. How you decide which column to filter can be based on text before the : (per your example) character or you can provide a drop down to select the column that the search input would apply to.You can use
columns.searchable
to disable search on some columns - but it sounds like you want something more complex than that - retain search on all columns, but allow the user to enter text which will limit the search.There is no built in option for that, but it would be possible to build such a filter using a custom search plug-in.
Allan
Ok, thanks to your answers.
I develop this now and works like a charm.
BR