i have below code for generating jquery datatable in my spring mvc project . but i loading the page , the javascript throwing some warning.
var sTable = $('#tblKeyDetails').dataTable({
"aoColumns" : [ null,null, null,null],
"sPaginationType" : "full_numbers",
});
$.ajax({
dataType : 'json',
type : 'GET',
url : 'getKeyDetails.html',
data :({
form : $('#ddlKeyStatus').val()
}),
beforeSend : function() {
//startPreloader();
},
complete : function() {
//stopPreloader();
},
success : function(data) {
sTable.fnClearTable();
$.each(data, function(index,item) {
var rowCount = index+1;
sTable.fnAddData( [ '<label align="center">'+rowCount+'</label>',
item['key'],
item['date'],
item['userEmail']
]);
});
}
});
response objects contain
date: null
deviceId: null
id: 3
key: "DQAIYLFFDVFG"
userEmail: null
userId: 0
change this:
sTable.fnAddData( [ '<label align="center">'+rowCount+'</label>',
item['key'],
item['date'],
item['userEmail']
]);
to
sTable.fnAddData( [ '<label align="center">'+rowCount+'</label>',
item['key']!=null ? item['key'] : "",
item['date']!=null ? item['date'] : "",
item['userEmail']!=null ? item['userEmail'] : ""
]);
preventing null values will fix your issue. You can also disable datables warning messages but fix the problem could be better.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.