$(document) .ready( function() { $.tablesorter.addParser({ // use a unique id id : 'number', 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 $(cell).attr('data-value'); }, // flag for filter widget (true = ALWAYS search parsed // values; false = search cell text) parsed : false, // 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' }); $('#myTable').tablesorter({ cssChildRow: "subcategory", widget: ['zebra'], headers: { 2: { sorter: 'number' }, 4: { sorter: 'number' }, } }); }); function showChildren(id){ var status=$('.parent_'+id).data('value'); $('.'+id).each(function(index,row){ if(status==0){ $(row).css('display',""); } else { $(row).css('display','none'); } }); if(status==1){ $('.parent_'+id).data('value',0); } else { $('.parent_'+id).data('value',1); } }