1
我使用舊的tablesorter插件。使用tablesorter插件對組合框進行排序
在我的表中,我有一列可排序的組合框。
但是,當我更改其值時,我無法使組合框正確排序。
我有這樣的事情(修改,節選):
function sortTable(columnId, sortOrder) {
if (columnId && sortOrder) {
// previous settings available
var columnIndex = $("#" + columnId).index();
// determine sort index
var sortIndex = -1;
if ("asc" == sortOrder) {
sortIndex = 0;
} else if ("desc" == sortOrder) {
sortIndex = 1;
}
// sort table
if (sortIndex > -1) {
$('#table1').tablesorter({
textExtraction: function(node) {
// special processing for combobox
if ($(node).find('option:selected').text() != "") {
var selected = $(node).find('option:selected').text();
return selected;
} else {
return $(node).text();
}
},
sortList: [[columnIndex, sortIndex]]
});
}
} else {
// no previous settings available
$('#table1').tablesorter({
textExtraction: function(node) {
// special processing for combobox
if ($(node).find('option:selected').text() != "") {
var selected = $(node).find('option:selected').text();
return selected;
} else {
return $(node).text();
}
}
});
}
當我點擊表頭時調用此函數。
$("#table1 th").click(function() {
var sortInfo = determineColumnIdToSort();
var sortOrder = determineNewSortOrder();
removeTablesorter(); // removes binds to the tableSorter
sortAssignMeasuresTable(columnId, sortOrder);
});
我的問題是:
如果我有不同的價值組合框,他們會正確排序,當我點擊標題。但是,如果我改變,爲組合框選擇另一個值,排序不能正常工作。即使它應該被排序,組合框仍然保持在相同的位置。