0
我有像「firstValue secondValue」列中的數據。這些數據必須在一列(我不能做兩列)。當我設置排序時,它按firstValue和secondValue排序。現在我想改變一些事件來按secondValue排序數據(忽略firstValue)。在另一個事件之後,我想按firstValue進行排序。這可能嗎?我怎樣才能做到這一點?如何在點擊按鈕後更改列排序類型? [jQuery,DataTables]
我有像「firstValue secondValue」列中的數據。這些數據必須在一列(我不能做兩列)。當我設置排序時,它按firstValue和secondValue排序。現在我想改變一些事件來按secondValue排序數據(忽略firstValue)。在另一個事件之後,我想按firstValue進行排序。這可能嗎?我怎樣才能做到這一點?如何在點擊按鈕後更改列排序類型? [jQuery,DataTables]
這可能太晚了,但我剛剛遇到了同樣的問題。該解決方案涉及custom sorting和altering the table settings in the event handler的組合。
一些代碼,使其更加具體:
$.extend($.fn.dataTableExt.oSort, {
"secondValue-pre": function (a) {
var parts = a.split(' ')[1];
},
"secondValue-asc": function (a, b) { return ((a < b) ? -1 : ((a > b) ? 1 : 0)); },
"secondValue-desc": function (a, b) { return ((a < b) ? 1 : ((a > b) ? -1 : 0)); }
});
var $myTable = $('#example').dataTable({
"aoColumns": [
null, //your column containing "firstValue secondValue"
null,
]
});
$(document).ready(function() {
$('.something').click(function() {
var oSettings = $myTable.fnSettings();
oSettings.aoColumns[0].sType = 'secondValue';
});
});
我敢肯定,有許多方法來改善這個代碼,但它應該讓你開始。