Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define some sorting functions
- function NumericSorter(a, b) {
- var x = a[sortcol], y = b[sortcol];
- return sortdir * (x == y ? 0 : (x > y ? 1 : -1));
- }
- function RatingSorter(a, b) {
- var xrow = a[sortcol], yrow = b[sortcol];
- var x = xrow[3], y = yrow[3];
- return sortdir * (x == y ? 0 : (x > y ? 1 : -1));
- }
- // Configure the columns
- var columns = [
- {id:"published", name:"Published", field:"published", sortable: true, sorter:NumericSorter, formatter:DateCellFormatter},
- {id:"title", name:"Title", field:"title", sortable: true, sorter:NumericSorter, formatter:TitleCellFormatter},
- {id:"publisher", name:"Publisher", field:"publisher", sorter:NumericSorter, sortable: true},
- {id:"rating", name:"Rating", field:"rating", sortable: true, sorter:RatingSorter, formatter:RatingCellFormatter},
- ];
- $(function() {
- var grid = new Slick.Grid(".datatable", data_view.getItems(), columns, options);
- grid.onSort.subscribe(function(e, args) {
- sortdir = args.sortAsc ? 1 : -1;
- sortcol = args.sortCol.field;
- data_view.sort(args.sortCol.sorter, sortdir);
- args.grid.invalidateAllRows();
- args.grid.render();
- });
- });
Add Comment
Please, Sign In to add comment