Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用tablesorter插件使用combobox对表进行排序_Jquery_Tablesorter - Fatal编程技术网

Jquery 使用tablesorter插件使用combobox对表进行排序

Jquery 使用tablesorter插件使用combobox对表进行排序,jquery,tablesorter,Jquery,Tablesorter,我正在使用旧的tablesorter插件 在我的表中,有一列可排序的组合框。 但是,当我更改组合框的值时,我无法使它们正确排序 我有这样的东西(修改,摘录): 当我单击表格标题时调用此函数 $("#table1 th").click(function() { var sortInfo = determineColumnIdToSort(); var sortOrder = determineNewSortOrder(); removeTablesorter(); // r

我正在使用旧的tablesorter插件

在我的表中,有一列可排序的组合框。
但是,当我更改组合框的值时,我无法使它们正确排序

我有这样的东西(修改,摘录):

当我单击表格标题时调用此函数

$("#table1 th").click(function() {
    var sortInfo = determineColumnIdToSort();
    var sortOrder = determineNewSortOrder();
    removeTablesorter(); // removes binds to the tableSorter
    sortAssignMeasuresTable(columnId, sortOrder);
});
我的问题是:

如果我有不同值的组合框,当我点击标题时,它们会正确排序。但是如果我改变,为组合框选择另一个值,排序将无法正常工作。组合框将保持在相同的位置,即使它应该被排序。

原始版本的tablesorter有一个方法来
updateCell
,但是在这种情况下,它没有正确地索引要更新的单元格,因此您需要触发一个完整的
更新,这在大型表中不是很有效。希望您至少正在使用jQuery 1.7+,如果您正在使用,那么请使用以下代码():


如果您感兴趣,我已经添加了解析器来更新select、input和checkbox。您可以在这里看到这些解析器的作用。

原始版本的tablesorter有一个方法来
updateCell
,但是在这种情况下,它没有正确地索引要更新的单元格,因此您需要触发一个完整的
更新
,这在大型表中不是很有效。希望您至少正在使用jQuery 1.7+,如果您正在使用,那么请使用以下代码():

如果您感兴趣,我已经添加了解析器来更新select、input和checkbox。您可以在本文中看到这些解析器正在运行

$("#table1 th").click(function() {
    var sortInfo = determineColumnIdToSort();
    var sortOrder = determineNewSortOrder();
    removeTablesorter(); // removes binds to the tableSorter
    sortAssignMeasuresTable(columnId, sortOrder);
});
// Custom parser which returns the currently selected options
// updated dynamically using the "change" function below
$.tablesorter.addParser({
    id: "select",
    is: function () {
        return false;
    },
    format: function (s, table, cell) {
        return $(cell).find('select').val() || s;
    },
    type: "text"
});

// update select in the tablesorter cache when the change event fires.
// This method only works with jQuery 1.7+
// you can change it to use delegate (v1.4.3+) or live (v1.3+) as desired
// if this code interferes somehow, target the specific table $('#mytable'),
// instead of $('table')
$(window).load(function () {
    // this flag prevents the update event from being spammed
    var alreadyUpdating = false;
    $('table').find('tbody').on('change', 'select', function (e) {
        if (!alreadyUpdating) {
            alreadyUpdating = true;
            $(this).trigger('update');
            setTimeout(function () {
                alreadyUpdating = false;
            }, 10);
        }
    });
});

$('table').tablesorter({
    headers: {
        1: {
            sorter: 'select'
        }
    }
});