Easy sortable HTML tables using jQuery
Published
I made a little jQuery script that makes it really easy to enable sorting on a HTML table.
Features
- Really easy to set up
- Can sort on load if a header is specified otherwise assumes that the first column is already sorted
- Keyboard accessible
- Adds
title
attributes automatically to eachth
- CSS arrow to signify ascending or descending
How to use
- Create a
table
usingtbody
tags for content andth
for headers - Add
sortable
class to the table - (Optional) Specify a
th
to be sorted when the document is ready by adding the classsorted
orsorted desc
for descending