tablesorter - Jquery tablesort -


i using tablesorter jquery , using page example

http://mottie.github.io/tablesorter/docs/example-parsers.html

and using plugin:

http://mottie.github.io/tablesorter/js/jquery.tablesorter.js

this code sort "status"

$.tablesorter.addparser({       id: 'status',       is: function(s) {         // return false parser not auto detected         return false;       },       format: function(s, table, cell, cellindex) {         // format data normalization         //console.log(cellindex);         return s.tolowercase()           .replace(/deleted/,4)           .replace(/finished/,3)           .replace(/cancelled/,2)           .replace(/in progress/,1)           .replace(/new/,0);       },       // set type, either numeric or text       type: 'numeric'     });  $('#request').tablesorter(         {             debug:false,              widthfixed: false,             headers: {                 0: { sorter: false },                 3: { sorter: false },                 4: { sorter: 'dates-desired' },                 6: { sorter: 'dates-projected' },                 7: { sorter: 'status' },                 8: { sorter: false },             }         }     ); 

but when click status thead, nothing happens

when make debug option: true, o/p:

"sorting on 7,0 , dir 0 time (1ms)" jquery.tablesorter.min.js:157:5

"rebuilt table (4ms)" jquery.tablesorter.min.js:157:5 "completed

applying 0 widgets (0ms)"

any appreciated.

the issue in within parser code... text set lower case, regex contains upper case characters. try updated parser:

var arry = [ 'new', 'in progress', 'cancelled', 'finished', 'deleted' ]; $.tablesorter.addparser({     id: 'status',     is: function() {         // return false parser not auto detected         return false;     },     format: function( s, table, cell, cellindex ) {         var str = ( s || '' ).tolowercase(),             index = arry.indexof( str );         // return original text if index not found; allows proper         // sorting of empty cells         return index < 0 ? s : index;     },     // set type, either numeric or text     type: 'numeric' }); 

if need support older versions of ie, change using indexof jquery's $.inarray() function

index = $.inarray( str, arry ); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -