Sort only one column with jquery and tablesorter

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 03:16:33

问题


At the moment im using jquery tablesorter and tablesorter filter. My problem is that i want that my filter would filter only one column. Now its filtering all columns. You can see my site here: http://tinyurl.com/3j38vye

Now its filtering all colums and i'd like to filter only "Lainasumma" column. Could you also say why its not sorting amounts properly?


回答1:


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

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

Edit

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

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
            }
        }
    });
});



回答2:


The easiest solution for that is to modify the selectorHeaders in the javascript file and set it to something other like:

 selectorHeaders: 'thead th.sortable'

Now, the only thing you have to do is to give only the collumns you want to be sortable the css class sortable.




回答3:


I can tell you that it is not sorting the amounts properly because the sorting don't treat the amounts columns as numbers and instead it treats them as text so it is sorting them text based.



来源:https://stackoverflow.com/questions/7849558/sort-only-one-column-with-jquery-and-tablesorter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!