DT_RowId and RowClass

DT_RowId and RowClass

genialgenial Posts: 9Questions: 0Answers: 0
edited October 2011 in DataTables 1.8
HI ,
I could able to generated json with DT_RowId and DT_RowClass, but datatables is not able to parse it.
This the generated code from the server (json)
[code]
{"0": "Gecko",
"1": "Firefox 1.0",
"2": "Win 98+ / OSX.2+",
"3": "1.7",
"4": "A",
"DT_RowId": "row",
"DT_RowClass": "Class"
},
{"0": "Gecko",
"1": "Firefox 1.5",
"2": "Win 98+ / OSX.2+",
"3": "1.8",
"4": "A"
,"DT_RowId": "row",
"DT_RowClass": "Class"
}
[/code]


Thank you,

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2011
    is that your entire JSON?

    DataTables requires that the data above be put into a variable inside a master object. the variable is traditionally named aaData (you can change this by specifying an alternate sAjaxDataProp . see http://www.datatables.net/ref#sAjaxDataProp)

    also your aaData should be an array of arrays, or array of objects. note the square brackets used below "[" and "]"

    [code]
    {
    "aaData": [
    {"0": "Gecko",
    "1": "Firefox 1.0",
    "2": "Win 98+ / OSX.2+",
    "3": "1.7",
    "4": "A",
    "DT_RowId": "row",
    "DT_RowClass": "Class"
    },
    {"0": "Gecko",
    "1": "Firefox 1.5",
    "2": "Win 98+ / OSX.2+",
    "3": "1.8",
    "4": "A"
    ,"DT_RowId": "row",
    "DT_RowClass": "Class"
    }]
    }
    [/code]

    in the AJAX/JSON example http://www.datatables.net/release-datatables/examples/data_sources/ajax.html
    here is the JSON used: http://www.datatables.net/release-datatables/examples/ajax/sources/arrays.txt
  • aykutarasaykutaras Posts: 2Questions: 0Answers: 0
    Hi,
    i am getting the same problem.
    Current problem is datatable have not parsed array of objects but it parses array of arrays correctly,

    My working json code:
    [code]
    {"sEcho":1,"iTotalRecords":3,"iTotalDisplayRecords":3,"aaData":[["Residential","Residential Card1","Active"],["Vehicle","Vehicle Scoring Card","Passive"],["Personal","Personal Scoring Card","Passive"]]}
    [/code]

    in this example my json code is array of arrays and it works quite well. But the thing is i can not set DT_RowId and DT_RowClass properties to an array. Instead i need to use an object.

    And not working example datatables gives "DataTables warning (table id = 'tblScoringList'): Requested unknown parameter '0' from the data source for row 0" error. Here is my json code:
    [code]
    {"sEcho":1,"iTotalRecords":3,"iTotalDisplayRecords":3,"aaData":[{"Loan":"Residential","Name":"Residential Card1","Status":"Active"},{"Loan":"Vehicle","Name":"Vehicle Scoring Card","Status":"Passive"},{"Loan":"Personal","Name":"Personal Scoring Card","Status":"Passive"}]}
    [/code]

    in this example my json code is array of objects and i think the problem is in here.
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited October 2011
    @aykutaras: if you want to use the object form of aaData, your aoColumns/aoColumnDefs should reference the fields/columns by mDataProp so it knows which field to match in the resulting aaData

    http://www.datatables.net/ref#mDataProp
    http://www.datatables.net/blog/Extended_data_source_options_with_DataTables
    http://www.datatables.net/usage/server-side
  • aykutarasaykutaras Posts: 2Questions: 0Answers: 0
    Thank you. That is the thing i was looking for. Now it works well.
This discussion has been closed.