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

Filtering using a natural sort #1490

Closed
bogal opened this issue Dec 31, 2017 · 4 comments
Closed

Filtering using a natural sort #1490

bogal opened this issue Dec 31, 2017 · 4 comments

Comments

@bogal
Copy link

bogal commented Dec 31, 2017

In my app i have a column that can have digits 1-10 (including decimals), or the string 'All'. I am able to sort these columns with the following code:

$("table").tablesorter({ textSorter: { 1: function(a, b) { x = parseFloat(a); y = parseFloat(b); return x === 0 && y === 0 ? b.length - a.length : $.tablesorter.sortNatural(a, b); } }, });

... i was wondering if the same can be applied to filtering? I am using the filter widget and whilst it works as it should, would like the filtering to always include rows with 'All' in the results? So when the dropdown is populated with the values from the table, say the user selects 3, all rows containing 3 and All are filtered. This should only happen on this column, other columns that are filterable(?) should not have this behaviour.

@Mottie
Copy link
Owner

Mottie commented Dec 31, 2017

Hi @bogal!

I'm not exactly sure what you mean.

If you want rows with "All" to always show, then try the following code (demo):

$(function() {
  $("table").tablesorter({
    theme: "blue",
    widgets: ["zebra", "filter"],
    widgetOptions: {
      filter_defaultFilter: {
        // "all" will always show
        1: "{q}|all"
      }
    }
  });
});

@bogal
Copy link
Author

bogal commented Jan 1, 2018

Again, thanks for the quick reply. Your interpretation of the issue is spot on, and although the fiddle shows exactly what i am looking to achieve, it isn't working on my site. On mine (i should have stated), i am not using an input to filter the results, but the select (dropdown) box - that is the only difference between them.

@Mottie
Copy link
Owner

Mottie commented Jan 1, 2018

What I think you need then is to add the following classes to the header (demo & ref):

<th class="filter-select filter-match">Numeric</th>

@bogal
Copy link
Author

bogal commented Jan 1, 2018

Works perfectly. Thanks for taking the time to help, much appreciated :)

@bogal bogal closed this as completed Jan 1, 2018
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