Unable to load JSON data

Unable to load JSON data

mathieufanneemathieufannee Posts: 17Questions: 0Answers: 0
edited September 2011 in General
Hello,

I'm new to DataTables. The problem I have is that I can't manage to get my table (sent as JSON from the server) loaded into DataTables. I read quite a part of the documentation, but I'm really not getting what I am doing wrong. Do you?

Here is the code:

[code]





$(document).ready(function() {


var oTable = $('#list').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "../nl.inl.gigantcom/gigant/table/wordforms",
"sAjaxDataProp": "aaData",
"aoColumnDefs": [
{ "sName": "wordform", "aTargets": [ 0 ] },
{ "sName": "has_analysis", "aTargets": [ 1 ] },
{ "sName": "document_id", "aTargets": [ 2 ] }
],
"fnDrawCallback": function() {

if ( typeof oTable != 'undefined' ) {

$('td', oTable.fnGetNodes()).editable( '../nl.inl.gigantcom/gigant/table/wordforms/', {
"callback": function( sValue, y ) {
var aPos = oTable.fnGetPosition( this );
oTable.fnUpdate( sValue, aPos[0], aPos[1] );
},
"submitdata": function ( value, settings ) {
return {
"row_id": this.parentNode.getAttribute('id'),
"column": oTable.fnGetPosition( this )[2]
};
},
"height": "14px"
} ) }
}
} );

});













Woordvorm
Analyse beschikbaar
ID van doc




Loading data from server





Woordvorm
Analyse beschikbaar
ID van doc








[/code]

And here is the JSON:

[code]

{
"sEcho":0,
"iTotalRecords":"10000",
"iTotalDisplayRecords":"72",
"aaData":[
{
"has_analysis":"f",
"DT_RowClass":"ClassA",
"document_id":"",
"DT_RowId":"42",
"wordform":"een woord"
},
{
"has_analysis":"f",
"DT_RowClass":"ClassA",
"document_id":"",
"DT_RowId":"40",
"wordform":"nog een woord"
},
{
"has_analysis":"t",
"DT_RowClass":"ClassA",
"document_id":"3",
"DT_RowId":"39",
"wordform":"en nog een woord"
},

(more and more...)

{
"has_analysis":"t",
"DT_RowClass":"ClassA",
"document_id":"0",
"DT_RowId":"83",
"wordform":"laatste woord"
}
]
}
[/code]

Do you guys see any reason why this table can't be loaded? I really don't get it?

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    sEcho should be a string. (the "s" is indication of string)

    I think since you are not using the array (simple) form of aaData, you will need to specify mDataProp in your aoColumns/aoColumnDefs ? not sure sName works. I could be wrong.

    [code]
    "aoColumnDefs": [
    { "mDataProp": "wordform", "aTargets": [ 0 ] },
    { "mDataProp": "has_analysis", "aTargets": [ 1 ] },
    { "mDataProp": "document_id", "aTargets": [ 2 ] }
    ],
    [/code]
  • mathieufanneemathieufannee Posts: 17Questions: 0Answers: 0
    edited September 2011
    Hello FBAS,

    Your solution works, thank you very, very much!
  • mathieufanneemathieufannee Posts: 17Questions: 0Answers: 0
    I think the change fbas was proposing about my code should also be applied in the documentation. On page http://www.datatables.net/usage/columns, in the section about sName, it says one can use this

    [code]
    "aoColumnDefs": [
    { "sName": "engine", "aTargets": [ 0 ] },
    { "sName": "browser", "aTargets": [ 1 ] },
    { "sName": "platform", "aTargets": [ 2 ] },
    { "sName": "version", "aTargets": [ 3 ] },
    { "sName": "grade", "aTargets": [ 4 ] }
    ]
    [/code]

    but it didn't work for me.
    Fortunately the following proposed by fbas did work:

    [code]
    "aoColumnDefs": [
    { "mDataProp": "engine", "aTargets": [ 0 ] },
    { "mDataProp": "browser", "aTargets": [ 1 ] },
    { "mDataProp": "platform", "aTargets": [ 2 ] },
    etc...
    ],
    [/code]
  • allanallan Posts: 63,531Questions: 1Answers: 10,474 Site admin
    http://www.datatables.net/usage/columns#mDataProp and http://www.datatables.net/usage/columns#sName perform different operations. "sName" is useful for naming columns, but it does not consume data like mDataProp does. To some extent sName has been depreciated by mDataProp now.

    Allan
  • mathieufanneemathieufannee Posts: 17Questions: 0Answers: 0
    Thank you for the info, and for your efforts.
This discussion has been closed.