Skip to content
Advertisement

Sort rows in table

I’m trying to sort rows in alphabetical order based on which column header is clicked using jQuery. It works fairly fine when debugging except that it doesn’t actually switch the rows in the HTML and so it doesn’t display a sorted table on the webpage. I’m using Thymeleaf th:text to populate the table body rows but for the sake of this example, I hardcoded some values. You can run it here: https://jsfiddle.net/tg2khrd4

Javascript:

JavaScript

HTML:

JavaScript

Advertisement

Answer

Once the td sorted… You just have to loop throught it and append it’s parent tr in the table…

JavaScript
JavaScript
Advertisement