4

I have simple HTML Table, I need to add sorting and grouping on every columns in jQuery.

<table cellspacing='0'>
<thead>
    <tr>
        <th>Task Details</th>
        <th>Progress</th>
        <th>Vital Task</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>Create pretty table design</td>
        <td>100%</td>
        <td>Yes</td>
    </tr>

</tbody>

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Waqas Zahoor
  • 69
  • 1
  • 1
  • 6

4 Answers4

4

You could use tablesorter for this. It's very simple to use.

$(document).ready(function() { 
   $("#myTable").tablesorter();  // <-- 'myTable' is the id of your table    
}); 

Here you could check a working demo

Claudio Redi
  • 65,896
  • 14
  • 126
  • 152
4

There are various plugins to perform this using jQuery. The most known one is jQuery tablesorter:

http://tablesorter.com/docs/

There are loads of such plugins here, pick the one you like most:

http://www.tripwiremagazine.com/2013/06/jquery-filter-sort-plugins.html

Filippos Karapetis
  • 4,317
  • 20
  • 38
4

I suggest using datatables, you use it like this:

$(document).ready(function(){
    $('#example').dataTable();
});
isJustMe
  • 5,384
  • 1
  • 29
  • 45
0

Do not reinvent the wheel. Use jquery tablesorter plugin.

DhruvPathak
  • 40,405
  • 15
  • 109
  • 170