我正在使用Datatables.net 1.10.19,并具有一个非常简单的表
var table = $('#table').DataTable({
dom: "<'col-lg-12 bgdark'<'row'<'col-sm-5'i><'col-sm-7'p>>>" +
"<'row'<'col-sm-12'tr>>" +
"<'col-lg-12 epic'<'row'<'col-sm-5'i><'col-sm-7'p>>>",
});
我的桌子看起来像这样
+-------+----------------------------------+-----------+
| Col1 | Col2 | Col3 |
+-------+----------------------------------+-----------+
| Name1 | <div data-param1="11">Text</div> | SomeText2 |
| | <div data-param2="9">Text</div> | |
| | <div data-param3="8">Text</div> | |
| Name2 | <div data-param1="7">Text</div> | SomeText2 |
| | <div data-param2="2">Text</div> | |
| | <div data-param3="1">Text</div> | |
| | | |
+-------+----------------------------------+-----------+
我想介绍一个点击事件,该事件将根据data-paramX
对表格进行排序,我不确定是否可以这样做?
$("#sortBy_param1").click(function () {
var order = table.order();
var lorder;
if (order[0][1] === "asc") {
lorder = "desc"
$('#sortBy_param1').html("<i class=\"fas fa-sort-down\"></i> Sort by X");
} else {
lorder = "asc"
$('#sortBy_param1').html("<i class=\"fas fa-sort-up\"></i> Sort by X");
}
table.order([?, lorder]).draw();
});