How to make search function point to the row without hiding other row?
How to make search function point to the row without hiding other row?

Hi, I am new to datatables and now currently doing the search function.
Datatables's search will point to the search result and hide the other row.
How can I make the search point to the search result but still containing other line?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Are you wanting to highlight the row containing the search term? If so, maybe the row().show() plugin will do what you want. Here is an example that also uses the Select Extension to highlight the row:
http://live.datatables.net/hatojihe/3/edit
Click the
Find Quinn
button.Kevin
Yes I want to highlight it but not using a button. But using the Search input and it should work same as your button "Find Quinn" works.
Please help me.
There are a couple options:
http://live.datatables.net/jorexujo/1/edit
Kevin
Hi, kthorngren can you kindly show me? I failed to do the first options and options 2 the example you provide me seem to still hiding the other row.
Here is an example that takes over the Datatables search input and uses row().show() along with the Select Extension to show the row:
http://live.datatables.net/hatojihe/34/edit
Type in a person's name in the table to show the row.
That example uses search(). Its a generic example I've used for other threads.
Kevin
Hi kthorngren, the example you gave me works perfectly on the link. But when I apply to my code, nothing happen. No error show too but it just did not work. Please noted that I am using real live data means data from database, is the method only works on hard coded data?
It is working now, thank you so much
Hi kthorngren, I have one more thing to ask. When user search, they need to key in the exact word for the search to function.
How can I make the search to work even when user key in one letter and the table will highlight all result that start with that letter?
The example I provided uses the row().show() plugin which takes only one row as a parameter to jump to and display the page. What you describe can potentially display more than one row which won't work with row().show().
You can change the comparison from
return data[0].toLowerCase() === val.toLowerCase();
to whatever meets your solution. Using regex will allow the search to be more flexible. I updated the example to show this:http://live.datatables.net/hatojihe/36/edit
Note that I changed
var row = table.row(function ( idx, data, node ) {
tovar row = table.rows(function ( idx, data, node ) {
to check all rows. Its nowtable.rows
with an s to userows()
. I also commented out the.show()
since it won't work with multiple rows. You could add some logic to useshow()
if the length of the rows is1
if you want.Kevin
Thank you so much Kevin, its help a lot. Now I will figure out how to show the row if the length is > 0.
Thank you