Search specific column in global search field

Search specific column in global search field

Borsti26Borsti26 Posts: 5Questions: 2Answers: 0

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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Have you looked at individual column searching?
    https://datatables.net/examples/api/multi_filter.html

  • Borsti26Borsti26 Posts: 5Questions: 2Answers: 0

    Sure, but this has one search field for each column i want to have only one field.
    BR

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    edited June 2017 Answer ✓

    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.

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin

    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

  • Borsti26Borsti26 Posts: 5Questions: 2Answers: 0

    Ok, thanks to your answers.

    I develop this now and works like a charm.

    BR

This discussion has been closed.