I've seen several examples of this problem but still haven't been able to find a resolution.
The error says it breaks on jquery.dataTables.js (version 1.10.4) on line 3287 shown below
// Got the data - add it to the table
for ( i=0 ; i<aData.length ; i++ ) {
_fnAddData( settings, aData[i] );
}
This is my controller. The controller is this way because the the lack of db connection right now, but will have JSON returned in the same format as $data. I have tried several things to resolve the error, but keep running into other issues. The JSON IS valid.
public function test()
{
$data = '{persons: [{branch: CORP,phone_numbers: [{desk: 5223422117},{mobile: 5022319224},{branch: 422-922-2291}],email: [email protected],preferred_name: Thomas,person_id: 368,department: IT,first_name: Thomas,title: Programming Manager,last_name: Williams}]}';
$data = json_encode($data);
echo $data;
}
My javascript
$(document).ready(function() {
$('#directory_table').dataTable( {
ajax: {
url: test,
type: JSON
},
aoColumns: [
{ persons: preferred_name },
{ persons: last_name },
{ persons: phone_numbers.0 },
{ persons: phone_numbers.1 },
{ persons: phone_numbers.2 },
{ persons: email },
{ persons: department },
{ persons: title }
]
} );
} );
My HTML
<table id='directory_table' class=display>
<thead>
<tr style='background: #186A9F; color: white;'>
<th>First Name </th>
<th>Last Name</th>
<th>Desk Number</th>
<th>Mobile</th>
<th>Branch</th>
<th>Email</th>
<th>Department</th>
<th>Title</th>
</tr>
<thead>
</table>