object nested not working

object nested not working

dalip09dalip09 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" }
]
});

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Can you post how it would look if you had two rows of data, please.

    Colin

  • dalip09dalip09 Posts: 4Questions: 1Answers: 0

    Row 1 = 52 | bkKnsne
    row 2 = 52 | nextusername

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I meant the JSON response.

    Colin

  • dalip09dalip09 Posts: 4Questions: 1Answers: 0

    {"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"}]}}

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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 be data.data.uid,

    Colin

  • dalip09dalip09 Posts: 4Questions: 1Answers: 0
    edited March 2020

    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"}]}}

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It appears to be working in the example I posted abive, so could you modify that to demonstrate the problem, please.

    Colin

This discussion has been closed.