I am developing a web project in Django and using jsGrid. I encountered a problem and couldn't find a solution.
I have a nested JSON data which is created by combinating multiple DB table records. Here is my JSON :
{
"count":3,
"results":[
{
"personnel":{
"name":"david",
"age":34
},
"company":"IBM"
},
{
"personnel":{
"name":"john",
"age":28
},
"company":"Google"
},
{
"personnel":{
"name":"Yuri",
"age":42
},
"company":"Microsoft"
}
]
}
Here is my js script:
function () {
$("#personnelsgrid").jsGrid({
height: "500px",
width: "100%",
filtering: !0,
editing: !0,
sorting: !0,
paging: !0,
autoload: !0,
pageSize: 15,
pageButtonCount: 5,
deleteConfirm: "Do you really want to delete the client?",
controller: {
loadData: function (filter) {
return $.ajax({
type: "GET",
url: "/get_personnels",
dataType: "json",
data: filter
});
}
},
fields: [
{name: "personnel.name", type: "text", width: 50},
{name: "personnel.age", type: "number", width: 50, filtering: false},
{name: "company", type: "text", width: 200},
]
As it is seen, I have a nested objects in my data. Although the JSON comes from the server, it is not loaded in jsGrid table. What should I do?
As in your response json data is coming in format of
response.results
. So, in yourloadData
method you need to pass yourresults
using$.Deferred()
like thisDEMO