dataSrc does not seem to be working
dataSrc does not seem to be working
Shinra
Posts: 2Questions: 1Answers: 0
Hi,
I have a json formatted like this:
{
"data": {
"table": [{
"id": 1,
"code": "VW",
"name": "View",
"description": "View",
"sorter": 0,
"deletedAt": null,
"createdAt": {
"date": "2018-02-17 08:37:13.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"createdBy": 0,
"updatedAt": {
"date": "2018-02-17 08:37:13.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updatedBy": null,
"rowVersion": 0
}, {
"id": 2,
"code": "DTL",
"name": "Detail",
"description": "Detail",
"sorter": 1,
"deletedAt": null,
"createdAt": {
"date": "2018-02-17 08:37:13.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"createdBy": 0,
"updatedAt": {
"date": "2018-02-17 08:37:13.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updatedBy": null,
"rowVersion": 0
}, {
"id": 3,
"code": "ADD",
"name": "Add",
"description": "Add",
"sorter": 2,
"deletedAt": null,
"createdAt": {
"date": "2018-02-17 08:37:13.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"createdBy": 0,
"updatedAt": {
"date": "2018-02-17 08:37:13.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updatedBy": null,
"rowVersion": 0
}]
}
}
I tried using dataSrc : 'data.table' but it is not working.
$(document).ready(function() {
$('#dataView').DataTable({
ajax: 'http://where.loc/api/sys/permission',
dataSrc: 'data.table',
columns: [
{ data: 'id' },
{ data: 'code' },
{ data: 'name' },
{ data: 'sorter' }
],
responsive: true
});
});
instead I got this error "Uncaught TypeError: Cannot read property 'length' of undefined".
could you tell what is wrong with my code, please?
EDIT: Updated code formatting using Markdown
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The
ajax.dataSrc
option needs to be within the ajax object. It should look like this:Kevin
wow, I totally miss that.
thank you for the fast response, kthorngren