我在datatable中添加了自定义排序功能。单击表标题时,它可以正常工作。但是,在pageLoad上,我希望使用与自定义排序函数中提供的逻辑相同的逻辑对该列进行排序。它似乎没有这样做。这是我的代码片段
$(document).ready(function(){
$("#stripedTableAcp").DataTable({
"columnDefs": [
{
"type": "acp_name",
"targets": 3
}
],
"order": [[ 3, "asc" ]],
"pageLength": 100,
"lengthMenu": [100, 500, 1000, 2000, 5000]
});
$.fn.dataTableExt.oSort["acp_name-desc"] = function (x, y)
{
console.log("1");
x = jQuery(x).text();
y = jQuery(y).text();
temp = x.split("-");
xPart1 = temp[0];
xPart2 = parseInt(temp[1]);
temp = y.split("-");
yPart1 = temp[0];
yPart2 = parseInt(temp[1]);
if(xPart1 > yPart1)
{
return -1;
}
if(xPart2 > yPart2)
{
return -1;
}
return 1;
};
$.fn.dataTableExt.oSort["acp_name-asc"] = function (x, y)
{
console.log("2");
x = jQuery(x).text();
y = jQuery(y).text();
temp = x.split("-");
xPart1 = temp[0];
xPart2 = parseInt(temp[1]);
temp = y.split("-");
yPart1 = temp[0];
yPart2 = parseInt(temp[1]);
if(xPart1 > yPart1)
{
return 1;
}
if(xPart2 > yPart2)
{
return 1;
}
return -1;
}
});
请注意,单击表标题但在页面加载时不会触发添加到函数的console.log
数据表版本是CDN提供的1.10.19
任何帮助是极大的赞赏。