PHP Dynamic Data Click table header sorting problem

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

 
  
Table header
Data

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

 
  
Table header
Data

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.
  • 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.