13

Anybody know of a plugin, or a built in function to make the columns in a table sortable? i.e. I click on the column header and it sorts the rows by that column?

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Gene R
  • 1,525
  • 5
  • 19
  • 31

6 Answers6

27

http://tablesorter.com/docs/ is very simple to use with a wide range of options to suit your needs. :)

Mike
  • 4,197
  • 3
  • 31
  • 47
3

http://www.flexigrid.info/

Flexigrid is a very popular, and easy table manager/sorter to use.

Kirk Woll
  • 73,473
  • 21
  • 178
  • 189
Remy Sharp
  • 4,470
  • 3
  • 22
  • 40
2

Here's two that sort and do many other things as well that I did not yet see listed :

Here is also a table comparing many data tables: http://blog.sematext.com/2011/09/19/top-javascript-dynamic-table-libraries/

SeanDowney
  • 16,768
  • 18
  • 79
  • 89
1

A little heavyweight, but the ultimate jQuery table manager is jqGrid

Javier
  • 58,927
  • 8
  • 76
  • 126
0

A jquery plugin that makes sort, filter and pagination: breedjs

Example:

Put the data in a js object to do just like so:

var data = {
    people: [
        {name: 'a', address: 'c', salesperson: 'b'},
        {name: 'b', address: 'b', salesperson: 'a'},
        {name: 'c', address: 'a', salesperson: 'c'},
    ]
};

breed.run({
    scope: 'people',
    input: data
});

HTML:

<table>
    <thead>
        <tr>
            <th sort='name'>Name</th>
            <th sort='address'>Address</th>
            <th sort='salesperson'>Sales Person</th>
        </tr>
    </thead>
    <tbody>
        <tr b-scope="people" b-loop="person in people">
            <td b-sort="name">{{person.name}}</td>
            <td b-sort="address">{{person.address}}</td>
            <td b-sort="salesperson">{{person.salesperson}}</td>
        </tr>
    </tbody>
</table>

Now, everytime you want to sort by salesperson, just call it:

breed.sort({
    scope: 'people',
    selector: //field name
});

See:

$("th").click(function(){
    breed.sort({
        scope: 'people',
        selector: $(this).attr('sort')
    });
});

Working example on fiddle

João Paulo
  • 5,760
  • 4
  • 44
  • 71
-1

The Ext JavaScript library is very good at that.

Diodeus - James MacFarlane
  • 110,221
  • 32
  • 151
  • 174