我在 jQuery DataTables 中使用服务器端处理,但行没有添加到表中。它们存在于 AJAX 成功中,并且行也在数据参数中,但它们没有添加到表中。
otable = $('#siteselectiontable').DataTable({
"serverSide": true,
"deferLoading": 0,
"processing": true,
"paging": true,
"columns": [{
"data":"RADIO"
},
{
"data":"SITE_DATA"
}
],
"ajax": {
success: function(data) {
if(typeof data['error']!="undefined"){
bootbox.alert({
closeButton: false,
message: "<div class='alert alert-danger' role='alert'>" +
"<strong>Timeout Error: </strong>Please refine your search" +
"</div>"
});
}
},
beforeSend: function() {
$("#siteselectionfooter").after(progress);
},
complete: function() {
$(".loading-mask").remove();
}
},
"searching": false,
"ordering": false,
"lengthChange": false,
"pageLength": 5,
"dom": '<"top"><"pull-right"f>t<"bottom center"p><"clear">',
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$('td:eq(0)', nRow).css({
'text-align': 'center',
'vertical-align': 'middle'
});
}
});
对于 ajax 调用,我使用以下内容:
table.ajax.url(url).load();
我已经用ajax选项中的
dataSrc
解决了这个问题,并添加了以下行
$.fn.dataTable.ext.errMode = 'none';
"ajax": {
beforeSend: function() {
$("#siteselectionfooter").after(progress);
},
complete: function() {
$(".loading-mask").remove();
},
"dataSrc": function ( json ) {
if(typeof json['error']!="undefined"){
bootbox.alert({
closeButton: false,
message: "<div class='alert alert-danger' role='alert'>" +
"<strong>Timeout Error: </strong>Please refine your search" +
"</div>"
});
}
return json.data;
}
},