Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter don't use textExtraction rules #149

Closed
1000i100 opened this issue Oct 9, 2012 · 8 comments
Closed

filter don't use textExtraction rules #149

1000i100 opened this issue Oct 9, 2012 · 8 comments

Comments

@1000i100
Copy link

1000i100 commented Oct 9, 2012

I use a custom function for textExtraction and it's perfect for sort actions. But the filter widget don't use it for filtering, it use the default text content instead.

Here an exemple :

html sample

<tr><td><span title="7 375 490 540">7,4G</span></td></tr>
<tr><td><span title="996 451 605">996M</span></td></tr>

JS config and textExtraction function

    var spanTitleSorter = function(node) 
    { 
        if($(node).text()=='-') return '-0.000001';
        if($('span[title]',node).length>0){
            floatRes = String(parseFloat($('span[title]',node).eq(0).attr('title').replace(/ /g,'').replace(/,/g,'.')));
            if(floatRes) return floatRes;
            else return $('span[title]',node).eq(0).attr('title').replace(/ /g,'').replace(/,/g,'.');
        } else return $(node).text();
    };
    $(".tabExplicit").tablesorter({
        textExtraction: spanTitleSorter,
        widgets: ['columns', 'filter', 'stickyHeaders', 'zebra'], 
    });

I hope an easy fix in the filter widget is possible !

@Mottie
Copy link
Owner

Mottie commented Oct 9, 2012

Hi GammaNu!

There is a filter widget option named filter_useParsedData which forces the filter widget to only use parsed data. Or, as shown in the documentation, you can alternately add filter-parsed to the header class name, or any of the other methods listed, to have the filter widget use parsed data for a single column.

I hope that clears things up! :)

@1000i100
Copy link
Author

Hi, i've seen that, but it look like an other way to get the same result, it don't change anything about textExtraction that's not used in filter widget, and so a fix could help the users, like me, who have used the textExtration property earlier.

But yes, i will use the other method to get it work fast ;)
Thank you !

@Mottie
Copy link
Owner

Mottie commented Oct 11, 2012

The textExtraction function is used to provide the text to the parser, so the column will sort by the parsed data. The filter widget will normally look at the contents of the cell and not the parsed data because users will want to look for a date like "Feb" instead of the parsed data value which is a really long number - the number of milliseconds since 1 January 1970 00:00:00 UTC (ref).

So you've got it all working now?

@1000i100
Copy link
Author

sure but with filter_useParsedData true, it don't use textExtraction func. It should, isn't-it ?

I've not tried an other way yet (not enougth time, i hope i will be able to try it soon)

@Mottie
Copy link
Owner

Mottie commented Oct 11, 2012

The textExtraction function is part of tablesorter's core. The filter_useParsedData is part of the filter widget. Setting the filter widget option to true will only make the filter widget look at the parsed data that was already obtained using the textExtraction function and column parsers.

Here is another way to say it:

  • textExtraction tells tablesorter where to look for data. Is it just text, or inside a span or image title?
  • The parsers (text, currency, shortDate, etc) tell tablesorter how to interpret the data it gets from the textExtraction function.
  • The filter_useParsedData (if true) tells the filter widget to use the data that the parsers obtained when it filters the rows, otherwise it looks at the raw table cell text (not HTML).

@1000i100
Copy link
Author

so this should work :

    $(".tabExplicit").tablesorter({
        textExtraction: myExtractionFunc,
        widgets: ['columns', 'filter', 'stickyHeaders', 'zebra'], 
    widgetOptions : {
        filter_useParsedData : true
    }
    });

and it don't :(

@Mottie
Copy link
Owner

Mottie commented Oct 14, 2012

Ahh, you're right! That causes a javascript error in the filter widget script. I'll have it fixed soon.

After the update, check out this demo

I've set the usNumberFormat option to false to make the formatFloat function properly parse numbers like this 1.234.567,89 or 1 234 567,89

Also the headers option needed the sorter set to digit and the textExtraction function reduced down to:

// extract text from the table
textExtraction: function(node) {
    if ($('span[title]', node).length > 0) {
        return $('span[title]', node).eq(0).attr('title');
    } else {
        var txt = $(node).text();
        return txt === '-' ? '-0.000001' : txt;
    }
}

@1000i100
Copy link
Author

Great ! It works perfectly ! Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants