numberSorter 函数仅适用于单个数字

numberSorter function only works with single digits

为了说明我的问题,我在 http://bootstrap-table.wenzhixin.net.cn/examples/

的示例页面上修改了 "Custom sort with null/undefined" fiddle

问题是示例中的数字排序很好,因为它们是一位数,但添加了两位数,例如 11,并且它不会将其视为数字。因此您得到例如 1、11、2而不是 1、2、11

新的fiddle是 enter code herehttp://jsfiddle.net/ctn6424h/

任何人都可以帮助改进 numberSorter javaScript 以便它实际上可以对数字进行排序吗?

numberSorter() 函数尝试以下代码:

function numberSorter(a, b) {
    if (!parseInt(a)) return -1 * getOrder();
    if (!parseInt(b)) return 1 * getOrder();
    if (parseInt(a) < parseInt(b)) return -1;
    if (parseInt(a) > parseInt(b)) return 1;
    return 0;
}

希望对您有所帮助。