Search results

Search results

adityag28adityag28 Posts: 28Questions: 6Answers: 0

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

  • adityag28adityag28 Posts: 28Questions: 6Answers: 0

    @kthorngren can you please take a look into this?

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    I would take a look at creating a sorting plugin for this.

    Kevin

  • adityag28adityag28 Posts: 28Questions: 6Answers: 0

    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.

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    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

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    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 time search event handler. The event handler calls draw() 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

  • adityag28adityag28 Posts: 28Questions: 6Answers: 0

    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!

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    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

  • adityag28adityag28 Posts: 28Questions: 6Answers: 0

    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!

  • adityag28adityag28 Posts: 28Questions: 6Answers: 0

    @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

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    Try using the search event and use order() to set the column order.

    Kevin

Sign In or Register to comment.