Unable to bind the received data to the DataTable.
Unable to bind the received data to the DataTable.

Here is the following code
$('#widow-grid').DataTable({
"searching": false, //this is disabled because I have a custom search.
"aaData": [data], //here we get the array data from the ajax call.
"columns": [
{"data":"family_code", title: "Family Codes"},
{"data":"District", title: "District"},
{"data":"Block", title: "Block"},
{"data":"Panchayat", title: "Panchayat"},
{"data":"Religion", title: "Religion"},
{"data":"Name", title: "Name"},
{"data":"Pension", title: "Pension"}
]
});
but When I checked the console no error is shown but neither is any data loaded into the datatable
I got the following records in console of data.
[{"family_code":"471","District":"Barabanki","Block":"Masauli","Panchayat":"Chilauki","Religion":"1","Name":"Shyamavati","Pension":"3"},{"family_code":"500","District":"Barabanki","Block":"Masauli","Panchayat":"Chilauki","Religion":"1","Name":"Phoolmati","Pension":"3"},{"family_code":"521","District":"Barabanki","Block":"Masauli","Panchayat":"Chilauki","Religion":"1","Name":"Suman Devi","Pension":"3"},{"family_code":"524","District":"Barabanki","Block":"Masauli","Panchayat":"Chilauki","Religion":"1","Name":"Shyamkali","Pension":"3"}]
Replies
As a side note you are using
aaData
which is a legacy Datatables optoin (1.9). You can continue to use that as Datatables 1.10 is backward compatible but its recommended to use the current form of the option which isdata
. The Conversion Guide provides a map between legacy and current naming convention.You have
"aaData": [data],
which is taking the array you already have and placing it inside another array. Try"aaData": data,
or better use"data": data,
.Kevin
Thanks for the info kevin, i also do above instructions but now i get the following errors.
DataTables warning: table id=widow-grid - Requested unknown parameter 'family_code' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
One more thing is that when I try to console.log(data.family_code); then I got undefined
Try
console.log(data[0].family_code);
to access the first element in the array.Your data and code works here:
http://live.datatables.net/powefiso/1/edit
Maybe you can update my example to show the unknown parameter error you are getting.
Kevin
Hello, kthorngren,
Your guidance helps me a lot. Actually, I need to parse JSON. then it works perfectly.
Thanks Again