嘿伙计们,所以我得到了这个数据表
var oTable = $("#products").dataTable({
"aaData": [
[1, "TEST1", "A"],
['NA', "NA1", "B"],
['NA', "NA2", "C"],
[4, "TEST2", "D"]
],
"aoColumns": [{
"sWidth": "70%",
"sClass": "center",
"bSortable": true,
"sType": "rankedNA"
}, {
"sWidth": "70%",
"sClass": "center",
"bSortable": false
}, {
"sWidth": "70%",
"sClass": "center",
"bSortable": false
}]
});
我需要自定义排序
jQuery.fn.dataTableExt.oSort['rankedNA-asc'] = function(a, b) {
return rankedNASort(a, b);
};
总是留下“NA'表格底部第一列中的值。无论是asc还是desc,NA都应该固定在底部
答案 0 :(得分:0)
jQuery.fn.dataTableExt.oSort["duration-desc"] = function (a, b) {
const z = naturalSort(a, b, 2) * -1;
return z;
};
jQuery.fn.dataTableExt.oSort["duration-asc"] = function (a, b) {
return naturalSort(a, b, 1);
}
function naturalSort (a, b, c) {
if(a === 'NA') {
if(c == 2) {
return 0
} else {
return 10000;
}
}
const a2 = parseInt(a);
const b2 = parseInt(b);
return a2 - b2;
}
为这种奇怪的缩进事先道歉......