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 ];
}
}