Search results
Search results
adityag28
Posts: 28Questions: 6Answers: 0
in DataTables
Hi, I am using the search bar functionality, but what I want is to show some results first and other later, based on the below requirement.
In this, the search keyword is stage, here I want to show the results with red underline first and then the ones with blue underline because the keyword stage comes first in those.
So how do I display the search results using this criteria?
This question has an accepted answers - jump to answer
Answers
@kthorngren can you please take a look into this?
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
I would take a look at creating a sorting plugin for this.
Kevin
As far I see it doesn't have what I need. I want to display those records first which have the searched keyword in the starting of the column values and then to display the rest of the records which contains the searched keyword.
What you are looking for is not built into Datatables. A custom sorting solution is needed. The sorting plugin is the way to create a custom sorting solution. Take a look at the published plugins for some examples.
Kevin
I had some time so I built this example:
http://live.datatables.net/neruzeki/1/edit
In addition to the sorting plugin I created an API that gets the column type. This is used by the
order
event to instantiate a one timesearch
event handler. The event handler callsdraw()
to force Datatables to order the table. Otherwise the table order won't change while searching.Sort the Position column then type
system
into the search input to see the results. The search plugin sort code seems to work but I only tested with this limited data set. Will leave it to you to perform more extensive testing.Kevin
I really appreciate the effort, thank you very much.
How do I include this api part if I have my own custom search box, please take a look at this link
http://live.datatables.net/neruzeki/2/edit
I have not added the search bar in html, just in jquery. I just want to know how to include the api part in the code, because there is a problem of reinitialisation of the table.
Thanks once again!
Did you follow the troubleshooting steps provided in at the link in the reinitialize error?
https://datatables.net/manual/tech-notes/3
You need to combine the two Datatables initializations into a single init as described here.
Kevin
Thanks, Kevin, the error is resolved now. I have marked your previous post as the answer.
Works really well.
DataTables is really good, I love it. It makes the work so easy. Great work guys!
@kthorngren
If I have the sorting applied on a different column, is there a way I could apply the sorting on the _Position _column whenever I search?
http://live.datatables.net/neruzeki/1/edit
Try using the
search
event and useorder()
to set the column order.Kevin