Search code examples
filtertablesorter

Filtering in Tablesorter. Unexpected behaviour


In my tablesorter I applied this addParser to the column I'm showing here in this question. And it works well, but I found an unexpected behaviour when I filter in a way.

The results without filtering will be like this next picture:

enter image description here

The code for the addParser is the next one:

$.tablesorter.addParser({ // set a unique id id: 'kilogramos', is: function(s) { // return false so this parser is not auto detected return false; }, format: function(s) { // format your data for normalization return parseFloat(s.replace(' Kg','').replace('.','')); }, // set type, either numeric or text type: 'numeric' });

If I use the ">=" it seems to apply the addParser, because I can get rid the "." and the " Kg" of and it finds the 11.689 Kg results.

enter image description here

But seems that if I don't use the operators like ">", or ">=", etc. the behaviour change and it needs the dot to find what you are trying to get. In the next pictures I show what I mean.

enter image description here In this last picture, I don't use the operators and I doesn't find any results. Instead, it needs now the "." and also even the " Kg" it works. The next image proves that:

enter image description here

I just don't want to need this "." or " Kg" to be used in any case.

Any help? Thanks


Solution

  • I think all you're missing is a "filter-parsed" class in the header (demo)

    <th class="sorter-kilogramos filter-parsed">Kg</th>