current position:Home>JQuery table sort

JQuery table sort

2021-08-27 00:19:55 momingliu

 

1. stay html Page head I quote <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"></script>

2. stay .js File loading tablesorter:
$("table tbody").append(html);
$("table").trigger("update"); table yes js Automatically generated , This sentence needs to be added during generation

3. stay .js Call... For the table to be sorted in the file tablesorter() Method :
  $('#tresult').tablesorter({headers:{0:{sorter:false}}});  # Cannot sort the first column

 

$(document).ready(function() { 
    $("table").tablesorter(); 
    $("#append").click(function() { 
        // add some html 
        var html = "<tr><td>Peter</td><td>Parker</td><td>28</td><td>$9.99</td><td>20%</td><td>Jul 6, 2006 8:14 AM</td></tr>"; 
        html += "<tr><td>John</td><td>Hood</td><td>33</td><td>$19.99</td><td>25%</td><td>Dec 10, 2002 5:14 AM</td></tr><tr><td>Clark</td><td>Kent</td><td>18</td><td>$15.89</td><td>44%</td><td>Jan 12, 2003 11:14 AM</td></tr>";         
        html += "<tr><td>Bruce</td><td>Almighty</td><td>45</td><td>$153.19</td><td>44%</td><td>Jan 18, 2001 9:12 AM</td></tr>"; 
        // append new html to table body  
         $("table tbody").append(html); 
        // let the plugin know that we made a update 
        $("table").trigger("update"); 
        // set sorting column and direction, this will sort on the first and third column 
        var sorting = [[2,1],[0,0]]; 
        // sort on the first column 
        $("table").trigger("sorton",[sorting]); 
        return false; 
    }); 
});
   
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.

 

copyright notice
author[momingliu],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2021/08/20210827001952632l.html

Random recommended