开发者

jQuery Tablesorter: addParser depending on css class of th-element?

I have to add own parsers to the default ones of the Tablesorter plugin. It is really easy and a mind fact, because it is the only way to be flexible with the plugin.

Usually you tell the p开发者_开发问答lugin which field should use a custom parser using the incremented id at table initialization, just like:

jQuery(".tablesorter").tablesorter({
    headers: {
        9: {
            sorter:'eur_currency' 
        }
    } 
});

Is it possible to link custom parser with css classes of th-elements? It would be nice, because the server-site program could decide wich parser is needet.


You could just include the metadata plugin and add the sorter to the class name - see this example. So your markup would look something like this:

<th class="{ sorter : 'eur_currency' }">Currency</th>

So, I have a fork of this plugin on github and thought this would be nice to add. Check out the demo page and download it from here. It will work with custom parsers, so just set the class to:

<th class="sorter-eu_currency">Currency</th>

I didn't test if underscores "_" work in the class name, but I think they do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜