Jquery tablesorter sort empty table cells

I have a table with a column with numbers spanning from about -10 to 10 and some empty columns.

I would like tablesorter to always put empty columns at the bottom of the table. Even if I sort ascending or descending.

Like this:

-1
0
2
3
<empty cell>
<empty cell>

or like this:

3
2
0
-1
<empty cell>
<empty cell>

Please note that my problem is the same as question 4792426 , except that I want the empty cells to be below when the sort order goes down and grows.

Deleting rows is not an option.

+5
source share
3 answers

I found a way to solve my problem.

ssell . , . !: -)

. , formatFloat formatInt, null : 0. tablesorter .

        $(document).ready(function () {
        $.tablesorter.formatInt = function (s) {
            var i = parseInt(s);
            return (isNaN(i)) ? null : i;
        };
        $.tablesorter.formatFloat = function (s) {
            var i = parseFloat(s);
            return (isNaN(i)) ? null : i;
        };
        $("#table").tablesorter();
    });

, , .

+7

jQuery tablesorter , / (, , "-" ), ( /).

<th class="{'sorter': 'digit', 'string': 'bottom'}">Count</th>

html/templates. , tablesorter.

$('table').tablesorter(
    headers: {
       1: { sorter: "digit", empty : "top" },
       2: { sorter: "digit", string: "bottom"}
    }
)

, , , k, v ​​ .

.

+2

If this can help anyone, here's how I did it for text.

function emptyAtBottomTextSorter(a, b, direction, column, table) {
    if (a == "") {
        a = direction ? "ZZZZZ" : "";
    }
    if (b == "") {
        b = direction ? "ZZZZZ" : "";
    }
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
}

$("#myTable").tablesorter({
    headers: {
        1 : {'sorter' : 'text'}
    },
    textSorter: {
        1 : emptyAtBottomTextSorter
    }
});

Works with Tablesorter v2.26.2

0
source

All Articles