ajaxProcessing是一個回調函數,允許您傳回問題中顯示的資料,或者隻傳回總行數(ref):
ajaxProcessing: function(data, table, xhr){
if (data && data.hasOwnProperty('rows')) {
var r, row, c, d = data.rows,
// total number of rows (required)
total = data.total_rows,
// all rows: array of arrays; each internal array has the table cell data for that row
rows = '',
// len should match pager set size (c.size)
len = d.length;
// this will depend on how the json is set up - see City0.json
// rows
for ( r=0; r < len; r++ ) {
rows += '
'; // new row
// cells
for ( c in d[r] ) {
if (typeof(c) === "string") {
rows += '
' + d[r][c] + ''; // add each table cell data to row
}
}
rows += '
'; // end new row
}
// find first sortable tbody, then add new rows
table.config.$tbodies.eq(0).html(rows);
// no need to trigger an update method, it's done internally
return [ total ];
}
}
在return [ total ];之前,如果在建構字元串時尚未完成,則可以使用方法查找行并添加類名。
或者,對伺服器的調用可以傳回已包含應用于行(ref)的類名的HTML字元串:
ajaxProcessing: function(data, table, xhr){
if (data && data.hasOwnProperty('rows')) {
// data.rows would look something like this
// '
r0c0r0c1r1c0r1c1'
return [ data.total, $(data.rows), data.headers ];
}
}