DEV Community

Discussion on: Jquery datatables Sorting

Collapse
 
pytesus profile image
pavan ツ • Edited

Thanks @rhymes & Ben.
After lots of research, I came across:
github.com/Mottie/tablesorter/issu...,

and used it like this:

//sorting for grades
    $(function() {
      $.tablesorter.addParser({
        id: 'grades',
        is: function() {
          return false; // do not auto-detect this parser
        },
        format: function(s) {
          var grades = ['A++','A+','A','B++','B+','B','C++','C+','C','A--','A-','B--','B-','C--','C-','NA'],
            index = grades.indexOf(s.toUpperCase());
          return index > -1 ? index : s;
        },
        type: 'numeric'
      });
      $('#datatable').tablesorter({ headers: { 6: {sorter:"grades"} } });
    });

Table is now getting sorted as expected :)