Unable to load JSON data
Unable to load JSON data
mathieufannee
Posts: 17Questions: 0Answers: 0
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?
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?
This discussion has been closed.
Replies
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]
Your solution works, thank you very, very much!
[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]
Allan