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,753
  • 72
  • 57
  • 129
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
  • 67,454
  • 15
  • 130
  • 155
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,367
  • 21
  • 39
4

I suggest using datatables, you use it like this:

$(document).ready(function(){
    $('#example').dataTable();
});
isJustMe
  • 5,452
  • 2
  • 31
  • 47
0

Do not reinvent the wheel. Use jquery tablesorter plugin.

DhruvPathak
  • 42,059
  • 16
  • 116
  • 175