object nested not working
object nested not working
dalip09
Posts: 4Questions: 1Answers: 0
I have the below Json response.
{"data":{"current_page":1,"last_page":52,"per_page":1,"total":52,"data":[{"uid":"bkKnsne","full_name":"Trevinder","email":"operations@b.solar","role":"admin"}]}}
I want to get "total" and I want to get uid. I have tried to below with no luck can someone please point me in the right direction.
var table = $('#tblReport').DataTable({
processing: true,
serverSide: true,
columns: [
{ data: "total" },
{ data: "data,uid" }
]
});
This discussion has been closed.
Answers
Can you post how it would look if you had two rows of data, please.
Colin
Row 1 = 52 | bkKnsne
row 2 = 52 | nextusername
I meant the JSON response.
Colin
{"data":{"current_page":1,"last_page":26,"per_page":2,"total":52,"data":[{"uid":"bkKnsne","full_name":"Trevinder","email":"operations@b.solar","role":"admin"},{"uid":"hpsyMGt","full_name":"Michael","email":"michael.d@b.solar","role":"admin"}]}}
You could do something like this. The first column is now displaying the records total by requesting the last JSON sent. For your second column, you would set the
columns.data
to bedata.data.uid
,Colin
I get the following error within the data tables
No matching records found
My Code
var table = $('#tblReport').DataTable({
processing: true,
serverSide: true,
ajax:"/Rest/TableUpdate",
"columns": [
{ "data": null, defaultContent: '', render: function() {
return table.ajax.json().total;}
},
{ "data": "data.data.uid" }
] });
**JSON Response **
{"data":{"current_page":1,"last_page":26,"per_page":2,"total":52,"data":[{"uid":"bkKnsne","full_name":"Trevinder","email":"operations@b.solar","role":"admin"},{"uid":"hpsyMGt","full_name":"Michael","email":"michael.d@b.solar","role":"admin"}]}}
It appears to be working in the example I posted abive, so could you modify that to demonstrate the problem, please.
Colin