Tablesorter and multi textExtraction in jQuery?

I have this table with the TableSorter plugin.

Jsbin # 1

enter image description here

However - I want column # 1 (second null) to be sorted with first char second char as digit!)

example:

4134 (I dont care about the other digits order - just the first one which is here=1)
22230 //2
242   //4
67    //7
28    //8
992222 //9

      

So I created another function textExtraction: (which will only apply on the first column)

    var myExtraction = function(node) {
  return parseInt($(node).substring(1))
}

      

and added another object to the ctor which is only for column # 1. (0).

...,{
    textExtraction: myExtraction,
    headers: {
        1: {
            sorter: 'digit'
        } 
    }
}

      

However, it is not ( jsbin # 2 is the new jsbin here ) and I'm pretty sure it isn't.

Any help please?

+3


source to share


1 answer


I'm not sure if you need a custom one myExtraction

at all. Just change the sorter for that column to 'text'

instead 'digit'

and it should work when you specify it with the rest of the headers.

Edit

If you want to use the second digit for sorting:



var myExtraction = function(node) {
  return $(node).text().substring(1);
}

jQuery('#bullsTable').tablesorter(
{
    headers: {
        0: {
            sorter: false
        },
        1: {
            sorter: 'text'
        },
        13: {
            sorter: 'digit'
        }, 
        14: {
            sorter: 'digit'
        }
    },
      textExtraction: jgExtraction,
      textExtraction: {
         1: myExtraction
      }
}

      

I have updated jsbin here .

Note. You were using an old version of tablesorter which it turned out to be not supported textExtraction

. I updated the tag <script>

and it works.

+3


source







All Articles