Sort only one column with jquery and tablesorter

前端 未结 3 1522
孤独总比滥情好
孤独总比滥情好 2021-01-05 17:26

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 c

3条回答
  •  半阙折子戏
    2021-01-05 17:57

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

提交回复
热议问题