Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Sorting hierarchical data?

I have tried for some time to work out a way of sorting nested categories with jQuery. I failed to build my own plugin to do this, so I tried to find something that were available already. Tried a few hours now with this one, http://www.jordivila.net/code/js/jquery/ui-widgetTreeList_inheritance/widgetTreeListSample.aspx and cant get it to work.

What are the alternatives of creating a jQuery / jQuery UI script that handles sorting children and parent categories in a way that can be combined with a AJAX PHP backend to handle the actual sorting in the database?

Thanks!

like image 489
Industrial Avatar asked Dec 14 '25 09:12

Industrial


1 Answers

You could try structuring your hierarchical data in your database using the Nested Set Model, it will allow you to simply query your categories in order of their depth using single SELECT

Here is an article from MySQL describing how it is implemented in a relational database http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

like image 126
3urdoch Avatar answered Dec 16 '25 21:12

3urdoch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!