[英]Ordering not working in JQuery datatables
我有一個用AJAX調用繪制在頁面上的數據表。 我需要對內容進行排序,以便默認情況下最新條目位於頂部。 但是,即使參數已更改,順序似乎也沒有任何變化,並且記錄是隨機列出的。
var InitiateViewOption = null;
var deviceId = null;
var deviceType = null;
var fromTime = null;
var toTime = null;
var keys = null;
function drawTable(from, to) {
var device = $("#device-details");
deviceId = device.data("deviceid");
deviceType = device.data("devicetype");
keys = device.data("attributes").split(",");
fromTime = from * 1000;
toTime = to * 1000;
if ( $.fn.dataTable.isDataTable( '#stats-table' ) ) {
var table = $('#stats-table').DataTable();
table.clear().draw();
table.ajax.reload();
}
else {
$("#stats-table").datatables_extended({
serverSide: true,
processing: true,
searching: false,
ordering: true,
pageLength: 100,
order: [[ 0, 'desc' ]],
ajax: {
url: "/devicemgt/api/stats/paginate",
data: buildAjaxData
}
});
}
}
function buildAjaxData (){
var settings = $("#stats-table").dataTable().fnSettings();
var obj = {
//default params
"draw" : settings.iDraw,
"start" : settings._iDisplayStart,
"length" : settings._iDisplayLength,
"columns" : "",
"order": "",
"deviceType" : deviceType,
"deviceId" : deviceId,
"from": fromTime,
"to" : toTime,
"attributes" : JSON.stringify(keys)
};
return obj;
}
盡管進行ordering : true
確實會啟用表標題附近的圖標,並且order: [[ 0, 'desc' ]]
根據降序設置圖標,但記錄的實際順序沒有變化,每個新記錄都在似乎隨機附加在表格中的某處。
也根據此鏈接上的答案嘗試了aaSorting : []
選項,但沒有更改
更新:確定未進行訂購的原因。 問題出在.datatables_extended({
函數中。一旦我將其更改為.DataTable({
然后將serverSide: false
,然后提供要進行排序的列,它就開始工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.