$(document).ready(function () {
$("#datatable").DataTable(),
$("#datatable-buttons")
.DataTable({
pageLength: 25,
lengthChange: 1,
buttons: ["copy", "excel", "pdf", "colvis"]
})
.buttons()
.container()
.appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)"),
$(".dataTables_length select").addClass("form-select form-select-sm")
});
这是我的数据表,但我想按 DESC 对值进行排序,我在代码中添加了“order:[2,"desc"]”,但它不起作用。
我做了一些调查,你问的是 JQuery Datatable,这与 ASP.NET 无关。
添加排序选项的代码是这样的:
$(document).ready(function () {
$("#datatable").DataTable(), // DataTable initialization with default sorting
$("#datatable-buttons")
.DataTable({
pageLength: 25,
lengthChange: 1,
buttons: ["copy", "excel", "pdf", "colvis"],
order: [[1, "desc"]] // Custom sorting by the second column in descending order
})
.buttons()
.container()
.appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)"),
$(".dataTables_length select").addClass("form-select form-select-sm")
});