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?
Asked
Active
Viewed 1.9k times
6 Answers
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
-
tablesorter! -- http://stackoverflow.com/a/9535584/665387 has link and example video – Ravi Ram Mar 02 '12 at 15:31
3
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
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')
});
});
João Paulo
- 5,760
- 4
- 44
- 71