Sort only one column with jquery and tablesorter

Im currently using jquery tablesorter and tablesorter filter. My problem is that I want my filter to filter only one column. Now it filters all the columns. You can see my site here: http://tinyurl.com/3j38vye

Now its filtering all columns, and I would like to filter only the "Lainasumma" column. Could you also say why sorting it is not enough?

+6
source share
3 answers

Have you looked at the documentation ? Here is an example of how you can disable some columns that use tablesorter. You can pass a headers object in which you can specify which columns are disabled.

An alternative method is to add class="{sorter: false}" to the cells on which you want to disable sorting.

Edit

You can use the $.tablesorter.addParser() method to define custom sorting (see jsFiddle example above).

The code

 $(document).ready(function() { $.tablesorter.addParser({ id: 'custom_sort_function', is: function(s) { return false; }, format: function(s) { // the € symbol causes the tablesorter to treat the value as a string // remove it and let the tablesorter treat it as numeric // use /\u20AC/ instead of /€/ if regex does not work as expected return s.replace(/€/, ''); }, type: 'numeric' }); $("#pikavipit").tablesorter({ headers: { 0: { sorter: false }, 1: { sorter: false }, 2: { sorter: 'custom_sort_function' }, 3: { sorter: false }, 4: { sorter: false }, 5: { sorter: false }, 6: { sorter: false }, 7: { sorter: false }, 8: { sorter: false } } }); }); 
+8
source

The easiest solution for this is to change selectorHeaders in the javascript file and set it to something else:

  selectorHeaders: 'thead th.sortable' 

Now the only thing you need to do is provide only the columns you want to sort, sorted by CSS class.

+6
source

I can tell you that it does not sort the amounts properly, because the sort does not treat the columns of the quantity as numbers, but instead processes them as text, so it sorts them based on the text.

0
source

Source: https://habr.com/ru/post/899787/


All Articles