Search Multiple Columns with priority

Search Multiple Columns with priority

alexcarvalhoalexcarvalho Posts: 3Questions: 1Answers: 0

Hi,
I have a simple datatables setup in my website, and for the general search field I want to prioritize a specific column (in my case the name column).
This is because when users search for something that is very common in other columns don't get a lot of responses that is not the one what their searching for.

Datatables have some in-built function to do this? Or I need to do this on my own? (seriously, I'm trying to figure out how to do this but nothing is coming in my mind).

Hope someone can help me,
Thank you.

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    If you want to limit to a specific column you can use column().search() with a your own search input. You could use column searches like these examples:

    https://datatables.net/examples/api/multi_filter.html
    https://datatables.net/examples/api/multi_filter_select.html

    Kevin

  • alexcarvalhoalexcarvalho Posts: 3Questions: 1Answers: 0

    Hi Kevin,

    Thank you for your answer,
    I figure out a way to do this manually but I'm not with much luck.

    Search for all the columns and store the data. Next search only in the specified column and overwrite the same entries array.

    My problem now is get the search result in a array to draw the table.

    Thank you,
    Alexandre.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Not sure I understand what you are doing. Is this with serverSide processing and you are working on your server script?

    Kevin

  • alexcarvalhoalexcarvalho Posts: 3Questions: 1Answers: 0

    No, I'm not using server side processing. Only frontend.

    Alexandre.

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Search for all the columns and store the data. Next search only in the specified column and overwrite the same entries array.

    I'm not sure what you are doing. Maybe you can post your code so we can see what it is you are doing.

    My problem now is get the search result in a array to draw the table.

    Once you have this array maybe you can explain what how you want to apply it to the table.

    Kevin

This discussion has been closed.