Ikram Hasib Ikram Hasib - 2 months ago 8
Ajax Question

DataTables RowsGroup plugin can't work when use JSON.stringify(responeText[1]) BUT manually declare data work fine

Manual Declare data (Work fine):

var data = [
["imran_15","David","Maths","80","20","10"],
["imran_15","David","Maths","80","20","10"],
["farhana_06","SIP/8002","03-09-2016","06:57:17am","03-09-2016","04:01:41pm"],
["imran_15","SIP/8001","03-09-2016","03:59:35pm","03-09-2016","09:55:14pm"],
["jannatul_66","SIP/8003","03-09-2016","10:15:34am","03-09-2016","10:26:26am"],
["jannatul_66","SIP/8003","03-09-2016","10:26:31am","03-09-2016","03:59:33pm"],
];


var data = JSON.stringify(responeText[1]); Output here:

[
["imran_15","David","Maths","80","20","10"],
["imran_15","David","Maths","80","20","10"],
["imran_15","David","Maths","80","20","10"],
["farhana_06","SIP/8002","03-09-2016","06:57:17am","03-09-2016","04:01:41pm"],
["imran_15","SIP/8001","03-09-2016","03:59:35pm","03-09-2016","09:55:14pm"],
["jannatul_66","SIP/8003","03-09-2016","10:15:34am","03-09-2016","10:26:26am"],
["jannatul_66","SIP/8003","03-09-2016","10:26:31am","03-09-2016","03:59:33pm"]


]

My JS:

var data = JSON.stringify(responeText[1]);
$('#table_id').DataTable({
"lengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "All"] ],
"columns": [
{
name: 'first',
title: 'Agent Name',
},
{
name: 'second',
title: 'Extension',
},
{
name: 'third',
title: 'Login Date',
},
{
name: 'fourth',
title: 'Login Time',
},
{
name: 'fifth',
title: 'Logout Date',
},
{
name: 'sixth',
title: 'Logout Time',
},
],
"data": data,


"rowsGroup": [
'first:name',
],
});


When show me some error:
First Alert: DataTables warning: table id=table_id - Requested unknown parameter '1' for row 0. For more information about this error, please see http://datatables.net/tn/4
Second Alert: DataTables warning: table id=table_id - Requested unknown parameter '1' for row 0. For more information about this error, please see http://datatables.net/tn/4

Please anyone help me.

Answer

The data property of DataTables expects an array, not a string, so you don't need to stringify the data at all:

var data = responeText[1];