Notes about the addParser template:

Add Parser Template

$.tablesorter.addParser({
  // use a unique id
  id: 'myparser',
  is: function(s, table, cell) {
    // s is the text from the cell
    // table is the current table (as a DOM element; not jQuery object)
    // cell is the current table cell (DOM element)
    // return false if you don't want this parser to be auto detected
    return false;
  },
  format: function(s, table, cell, cellIndex) {
    // s is the text from the cell
    // table is the current table (as a DOM element; not jQuery object)
    // cell is the current table cell (DOM element)
    // cellIndex is the current cell's column index
    // format your data for normalization
    // (i.e. do something to get and/or modify your data, then return it)
    return s;
  },
  // set the type to either numeric or text (text uses a natural sort function
  // so it will work for everything, but numeric is faster for numbers
  type: 'numeric'
});

Demo

Name Major Gender English Japanese Calculus Overall grades
Student01Languagesmale807075medium
Student02Mathematicsmale9088100good
Student03Languagesfemale859580good
Student04Languagesmale205065bad
Student05Mathematicsfemale707870medium
Student06Mathematicsmale446560bad

Javascript

Grades Parser Code


	

HTML

NOTE! Assigning the parser using a class name was added in version 2.0.11 (it is not part of the original plugin; use the headers option in older versions).


	

Next up: Writing custom parsers, advanced ››