AJAX call with nested JSON Data
AJAX call with nested JSON Data

I have a json source that I'd like to use inside a DataTable:
{
"tickets" : [ {
"ticket" : {
"locator" : "QWF2A8C6",
"status" : "new"
}
}, {
"ticket" : {
"locator" : "DNW18Y5T",
"status" : "new"
}
}, {
"ticket" : {
"locator" : "V3W32JFB",
"status" : "new"
}
} ]
}
In the ajax definition, 'tickets' has been added as the source to replace 'data' and the datatable is aware and shows 3 rows.
"ajax": {
"dataSrc": "tickets",
With the column defs:
columnDefs: [
{
title: "Locator",
data: "ticket.locator",
targets: 0
},
],
I've tried a number of 'data' definitions without success. They all result in a "DataTables warning: table id=dataTable - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4" error.
Can DataTables include data in this format? What would the correct syntax for the columnDef for data (ticket.locator does not work)?
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
Use
columns
instead ofcolumnDefs
as shown in this example:https://datatables.net/examples/ajax/deep.html
Kevin
Based on that example, my column definition would be as I entered it but this doesn't work:
columnDefs: [
{
title: "Locator",
"data": "ticket.locator",
targets: 0
},
Like I said don't use
columnDefs
. Usecolumns
. Like this:Kevin