Sorting of php dynamic data Click table headers

Source: Internet
Author: User
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?

 
Header
Data

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

 
Header
Data

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.