Search code examples
tablesorter

Different text used of sorting and filtering


in a app, I use jQueryTablesorter, and the widget https://mottie.github.io/tablesorter/docs/example-widget-filter.html

I have two main features : - filtering (the widget) - sorting (default feature)

Both of these feature use textExtraction() function,

https://mottie.github.io/tablesorter/docs/#textextraction

My problem is the following :

  • for sorting, I would like to use computer form of a date, that is "2020-04-01"
  • for filtering, I would like to use human form (in French "1er avril 2020").

How can I deal with it ?


Solution

  • I have found. I need to use a hook which modify the value parsed for filtering.

    $.tablesorter.filter.types.start = function(config, data) {
           data.exact = data.$cells[data.index];
           data.exact = data.exact.innerText;
           data.iExact = data.exact.toLowerCase();
           return null;
    }