Guest User

Untitled

a guest
Jul 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // Define some sorting functions
  2. function NumericSorter(a, b) {
  3. var x = a[sortcol], y = b[sortcol];
  4. return sortdir * (x == y ? 0 : (x > y ? 1 : -1));
  5. }
  6. function RatingSorter(a, b) {
  7. var xrow = a[sortcol], yrow = b[sortcol];
  8. var x = xrow[3], y = yrow[3];
  9. return sortdir * (x == y ? 0 : (x > y ? 1 : -1));
  10. }
  11.  
  12. // Configure the columns
  13. var columns = [
  14. {id:"published", name:"Published", field:"published", sortable: true, sorter:NumericSorter, formatter:DateCellFormatter},
  15. {id:"title", name:"Title", field:"title", sortable: true, sorter:NumericSorter, formatter:TitleCellFormatter},
  16. {id:"publisher", name:"Publisher", field:"publisher", sorter:NumericSorter, sortable: true},
  17. {id:"rating", name:"Rating", field:"rating", sortable: true, sorter:RatingSorter, formatter:RatingCellFormatter},
  18. ];
  19.  
  20. $(function() {
  21. var grid = new Slick.Grid(".datatable", data_view.getItems(), columns, options);
  22. grid.onSort.subscribe(function(e, args) {
  23. sortdir = args.sortAsc ? 1 : -1;
  24. sortcol = args.sortCol.field;
  25.  
  26. data_view.sort(args.sortCol.sorter, sortdir);
  27. args.grid.invalidateAllRows();
  28. args.grid.render();
  29. });
  30. });
Add Comment
Please, Sign In to add comment