Want to implement the Click Column header to sort, the contents of the table is dynamic Data, the table header output fixed, the content only one line (a tr) loop output, the code found on the web is fixed data sorted. A code that sorts dynamic data. It's better to write a little bit of code to make it easier to understand.
Reply to discussion (solution)
Only one row, how to show the result of sorting?
1 is actually very simple, if you do not consider the database load, but you can give you a simple demo.
You can use the JS of Sortdata () to trigger the event Ajax to request the database to be sorted in the order you want.
Note the Data-sort property behind it, which is the order of your current sort.
function SortData () { var sortstring = $ (". Head"). attr (' Data-sort '); Get your query criteria and sortstring //ajax request $ (". Data"). Remove ();//Erase Previous data //Splice data Replacement }
The principle is to replace an existing page label with a label after the query data is asynchronously requested
2. If you do not want to query the database then deliberately according to the data class to find all the labels and then use JS to sort out the page label replaced
No matter how you do it, you're going to have to replace the page's original sorted label element this is the main
1 is actually very simple, if you do not consider the database load, but you can give you a simple demo.
You can use the JS of Sortdata () to trigger the event Ajax to request the database to be sorted in the order you want.
Note the Data-sort property behind it, which is the order of your current sort.
function SortData () { var sortstring = $ (". Head"). attr (' Data-sort '); Get your query criteria and sortstring //ajax request $ (". Data"). Remove ();//Erase Previous data //Splice data Replacement }
The principle is to replace an existing page label with a label after the query data is asynchronously requested
2. If you do not want to query the database then deliberately according to the data class to find all the labels and then use JS to sort out the page label replaced
No matter how you do it, you're going to have to replace the page's original sorted label element this is the main
Well, thank you for reminding me that I have implemented, added a tag to the table header, given the trigger event for the parameter query database reload page implementation.