Php dynamic data Click table header sorting problem to achieve click column headers for sorting, the content in the table is dynamic data, the header output is fixed, the content is only one row (one tr) loop output, the code found on the Internet is sorted by fixed data. Find a dynamic data sorting code. It is better to write a little bit of code for easy understanding.
Reply to discussion (solution)
How can I display the sorting result with only one row?
1. it is actually very simple. if you don't consider the database load, you can give you a simple demo.
You can use the js trigger event of sortData () to send an ajax request to the database and sort it in the desired order.
Note that the following data-sort attribute records the order of your current sorting.
Function sortData () {var sortString = $ (". head "). attr ('data-sort '); // Obtain your query conditions and sortString // ajax request $ (". data "). remove (); // remove the previous data // replace the spliced data}
The principle is to use tags to replace existing page tags after querying data asynchronously.
2. if you do not want to query the database, find all the data labels based on the data class, sort them with js, and replace the page labels.
No matter how you implement it, you must replace the tag elements in the original order of the page. this is the main
1. it is actually very simple. if you don't consider the database load, you can give you a simple demo.
You can use the js trigger event of sortData () to send an ajax request to the database and sort it in the desired order.
Note that the following data-sort attribute records the order of your current sorting.
Function sortData () {var sortString = $ (". head "). attr ('data-sort '); // Obtain your query conditions and sortString // ajax request $ (". data "). remove (); // remove the previous data // replace the spliced data}
The principle is to use tags to replace existing page tags after querying data asynchronously.
2. if you do not want to query the database, find all the data labels based on the data class, sort them with js, and replace the page labels.
No matter how you implement it, you must replace the tag elements in the original order of the page. this is the main
Well, thanks for reminding me that I have already implemented this function. I have added the tag to the header, and configured the trigger event for parameter query database to reload the page.