An open API service indexing awesome lists of open source software.

https://github.com/dperrymorrow/jquery-sorter.js

sorts dom elements based on a numeric data field ASC, DESC
https://github.com/dperrymorrow/jquery-sorter.js

Last synced: 11 months ago
JSON representation

sorts dom elements based on a numeric data field ASC, DESC

Awesome Lists containing this project

README

          

#jquery.sorter.js
sorts DOM elements based on a data field. Works on tables, lists, divs ect...

## Usage

- select elements to sort, and data item to sort by
- take ASC or DESC as second param

### Say you have the following

````html





````
### And you run the following

````javascript
$('#table tr').sorter( 'num_key', 'DESC' );
````

### results in

````html





````

### You can also run custom sort functions as well such as sorting on a date string

````javascript
function compareDates(a,b){
var dateA = new Date( Date.parse(a) );
var dateB = new Date( Date.parse(b) );

if( dateA > dateB){ return -1; }
if( dateA < dateB ){ return 1; }
return 0
}

$('#table tr').sorter( 'date_key', 'DESC', compareDates );
````

### results in

````html





````