Simplify the code and error correction
Simplify the code and error correction
I'm using spring boot and datatable rowsGroup. I'm getting response from ajax call and load into data table. Once I draw the table, I also need to use rowsGroup. So do I need to destroy the table before using rowsGroup? If I destroy the table also, its working fine, otherwise "Cannot reinitialise DataTable" error arisen. But when I try to get data from ajax over time, its showing error "maximum call stack size exceeded". When I remove rowsGroup, no error. Please give a solution. And help me to simplify the code too. My code is below
$.ajax({
type : "GET",
url : " ${getFullfeedback}",
data : {'startDateValue' : startDateVal},
contentType : "application/json; charset=utf-8",
cache : false,
success : function(data) {
var table=$('#datatable').DataTable()
$('#datatable').dataTable().fnClearTable();
for (var i = 0; i < data.length; i++) {
$('#datatable').DataTable().row.add(
[
//few fields
data[i].feedback
]).draw();
}
table.destroy()
$('#datatable').DataTable({
dom: 'Bfrtlip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: {
columns: [ 0, ':visible' ]
}
},
'colvis'
],
columns: [
{
name: 'feedback',
title: 'Feedback',
}
], rowsGroup: [
'feedback:name'
] ,
pageLength: 30,
lengthMenu: [[12, 30, 60,90, -1], [12, 30, 60,90, "All"]]
})
},
error : function(data) {
$('#datatable').dataTable().fnClearTable();
console.log(data)
}
})
Answers
H @varman ,
There's some odd code here. At line 14 you're adding rows to a table, which you then destroy on line 21. It would be easier to let DataTables control the Ajax (
ajax
), or to just pass in the data from the Ajax response in withdata
,Cheers,
Colin