Ad

Best Way To Sort Data With JQuery And Laravel?

- 1 answer

I'm working on a Laravel app for searching case studies. Basically, I'm trying to figure out the best way to sort search results. The user may search for case studies by keywords, learning outcomes, or courses. When the results are returned, I'd like to provide the user with a way to sort the results.

For example, say I search a keyword and 10 case studies are returned as results. Each case study may have many learning outcomes and courses that are applicable to that case study. I'd like there to be a way for the user to select a filter like "only show me case studies that are applicable courses x and y". This seems like the kind of thing easily accomplished with jQuery.

Now, ideally i'd like to serve the results once and have this type of filtering take place on the front-end, however I'm stumped as to how I might represent this data in the DOM. Somehow I would need a way to select a case study from the results and grab the associated learning outcomes and courses from it. I don't think this is possible to do with data attributes because they can only hold one value and a case study can have many outcomes and many courses.

Alternatively, I could give each study a data-id and have it be the ID of the case study in the DB. When the user elects to sort the results a certain way, I could AJAX the ID's of the case studies, query the database for them and filter them on the Laravel back-end. However, this seems like a very inefficient way to do this because now i'm serving the same case studies twice and running unnecessary DB queries.

I apologize if this seems like a vague explanation, any pointers would be greatly appreciated.

Ad

Answer

Use jquery data tables with Laravel. You can find Laravel packages too.

Ad
source: stackoverflow.com
Ad