排序数据表下拉过滤器

时间:2014-02-23 16:34:23

标签: jquery datatables jquery-datatables

我有一个数据表,在那里我已经制作了用于过滤我的行的下拉列表。 我的问题是下拉列表中的值没有排序......

这是我的代码:

this.innerHTML = fnCreateSelect(oTable.fnGetColumnData(i), $("#" + i).val());
$('select', this).change(function () {
    var searchVal = $(this).val().replace(/\&/g, '&');
    if (searchVal != '') {
        searchVal = '^' + searchVal + '$';
    }
    oTable.fnFilter(searchVal, i, true, false);
});

谢谢!

1 个答案:

答案 0 :(得分:2)

好的,找到了答案:

所有需要做的就是写oTable.fnGetColumnData(i).sort()而不是oTable.fnGetColumnData(i)。 然后我也希望排序不区分大小写,所以我再次将其更改为:

oTable.fnGetColumnData(i).sort(function(a, b) {
    if (a.toLowerCase() < b.toLowerCase()) return -1;
    if (a.toLowerCase() > b.toLowerCase()) return 1;
    return 0;
});
相关问题