aoColumns works aoColumnsDefs doesn't, can't understand why
aoColumns works aoColumnsDefs doesn't, can't understand why
Since now i just used aoColumns to bind the colums from the records i extract from a db to the colums in the table.
I tried to switch to aoColumnDefs and it's making me literally going crazy because i don't get where i'm doing wrong.
Please help me, i've read all about this isse i could red, but i'm stuck and really frustrated.
Debugger results: http://debug.datatables.net/uyikoz
The aoColumnsDefs in my code:
i tried replacing mData with mDataProp. Even tried to replace columns identifiers with indexes (ex: "mData": "0" ), but no way.
[code]
"aoColumnsDefs": [
{ "mData": "engine"
, "target": [0]
} ,
{ "mData": "browser"
, "target": [1]
} ,
{ "mData": "platform"
, "target": [2]
} ,
{ "mData": "version"
, "target": [3]
} ,
{ "mData": "grade"
, "target": [4]
, "bSortable": false
, "bSearchable": false
}
] ,
[/code]
if i replace the above code with this one with aoColumns it works again
[code]
"aoColumns": [
{ "mData": "engine" } ,
{ "mData": "browser" } ,
{ "mData": "platform" } ,
{ "mData": "version" } ,
{ "mData": "grade", "bSearchable": false } ,
] ,
[/code]
Raw json i feed datatables with:
[code]
{
"sEcho": 1,
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
{
"engine": "Gecko",
"browser": "Firefox 1.0",
"platform": "Win 98+ / OSX.2+",
"version": "1.7",
"grade": "A",
"DT_RowClass": ""
},
...
... ,
{
"engine": "Gecko",
"browser": "Firefox 1.5",
"platform": "Win 98+ / OSX.2+",
"version": "1.8",
"grade": "A",
"DT_RowClass": ""
}
]
}
[/code]
I tried to switch to aoColumnDefs and it's making me literally going crazy because i don't get where i'm doing wrong.
Please help me, i've read all about this isse i could red, but i'm stuck and really frustrated.
Debugger results: http://debug.datatables.net/uyikoz
The aoColumnsDefs in my code:
i tried replacing mData with mDataProp. Even tried to replace columns identifiers with indexes (ex: "mData": "0" ), but no way.
[code]
"aoColumnsDefs": [
{ "mData": "engine"
, "target": [0]
} ,
{ "mData": "browser"
, "target": [1]
} ,
{ "mData": "platform"
, "target": [2]
} ,
{ "mData": "version"
, "target": [3]
} ,
{ "mData": "grade"
, "target": [4]
, "bSortable": false
, "bSearchable": false
}
] ,
[/code]
if i replace the above code with this one with aoColumns it works again
[code]
"aoColumns": [
{ "mData": "engine" } ,
{ "mData": "browser" } ,
{ "mData": "platform" } ,
{ "mData": "version" } ,
{ "mData": "grade", "bSearchable": false } ,
] ,
[/code]
Raw json i feed datatables with:
[code]
{
"sEcho": 1,
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
{
"engine": "Gecko",
"browser": "Firefox 1.0",
"platform": "Win 98+ / OSX.2+",
"version": "1.7",
"grade": "A",
"DT_RowClass": ""
},
...
... ,
{
"engine": "Gecko",
"browser": "Firefox 1.5",
"platform": "Win 98+ / OSX.2+",
"version": "1.8",
"grade": "A",
"DT_RowClass": ""
}
]
}
[/code]
This discussion has been closed.
Replies
Is wrong - it should be `aTargets` in DataTables 1.9- ( `targets` will be supported in 1.10+).
Allan
Same error, no colums data loaded. New debug info http://debug.datatables.net/elagog
As you can see i've changed the target with aTarget
[code]
"aoColumnsDefs": [{
"mData": "engine",
"aTargets": [0]
}, {
"mData": "browser",
"aTargets": [1]
}, {
"mData": "platform",
"aTargets": [2]
}, {
"mData": "version",
"aTargets": [3]
}, {
"mData": "grade",
"aTargets": [4],
"bSortable": false,
"bSearchable": false
}],
[/code]
Maybe i'm just blind and i can't see there is another small syntax error, i really can't understand. What could be possibly change simply replacing aoColumn with aoColumnDefs to make it stop working.
I've done another test: i tried to replace the json source so that it looks like this:
[code]
{
"sEcho": 1,
"iTotalRecords": "57",
"iTotalDisplayRecords": "57",
"aaData": [
{
"0": "Gecko",
"1": "Firefox 1.0",
"2": "Win 98+ / OSX.2+",
"3": "1.7",
"4": "A",
"5": ""
},
...
... ,
{
"0": "Gecko",
"1": "Firefox 1.5",
"2": "Win 98+ / OSX.2+",
"3": "1.8",
"4": "A",
"5": ""
}
]
}
[/code]
This way it wotks, but i would stick with aoColumn if i have to loose the names of the columns associated with their values.
Thanks for your help, i really appreciate.
and
> "0": "Gecko"
Doesn't align. Which do you want to use - objects with parameter names, or array indexes? They need to match. There is no `engine` property in the objects your JSON is returned, so it certainly won't work at the moment.
Allan
The first one, with parameter names, doesn't work. But the second one, with the indexes works. In both cases the datatable configuration was the same, that is, aoColumnDefs with mData plus parameter name. This is the configuration i posted above and the one i would like to use, if i can make it works.
When i tried to feed it with the second json i posted, i was just doing a random test. I tried that because in the debug info i posted i noticed the code i posted down here, in section [Table] > [Rows] > [Row0], [Row1] ...[RowN]
[code]
{
"0": null,
"1": null,
"2": null,
"3": null,
"4": null,
"engine": "Gecko",
"browser": "Firefox 1.0",
"platform": "Win 98+ / OSX.2+",
"version": "1.7",
"grade": "A",
"DT_RowClass": ""
}
[/code]
Thank you again.
Anyway, i would like to use the JSON with the form "engine": "Gecko", the one you can see in the last debug info i posted http://debug.datatables.net/elagog
When the debugger procuded those infos my datatable configuration was using aoColumnsDefs with "mData": "parameterName", "aTargets": [index]. This is the configuration i would like to use, but i can't get it works. If i just change aoColumnsDefs into aoColumns (and remove aTargets parameter) sticking with this very configuration and JSON source, it immediately back to work.
Thanks even for your the patience.
[code]
mDataProp_1=>engine
mDataProp_2=>browser
mDataProp_3=>platform
mDataProp_4=>version
[/code]
in the request paramters sent by the ajax call, because i need them to adjust the sql query. I manage to get those mDataProp if i use aoColumns but not if i use aoColumnsDefs (with aoColumnsDefs the table remains blank)
That's probably the problem. If you have a null value, you must specify sDefaultContent in order for DataTables to know what to do with a null value. Just set it to an empty string for example.
With that change, if you are still getting an error, what is the exact error you are getting?
The other thing is, why is the server returning so many rows? You've got server-side processing enabled, and it will request 10 rows only by default. So why is it returning a lot more than 10 rows?
Allan
DataTables warning (table id = 'example'): Requested unknown parameter '0' from the data source for row 0
i just tried to add sDefaultContent, no changes. Here the debug info of this last try http://debug.datatables.net/uyuyif
The results are more than 10 because i need the whole content of the table loaded (it would be a small table anyway) so i set bPaginate to false.
Thanks
In which case, don't enable server-side processing, since you don't want server-side processing.
> DataTables warning (table id = 'example'): Requested unknown parameter '0' from the data source for row 0
That means that it is using the DataTables default column detection. And I've just spotted why:
> aoColumnsDefs
Doesn't exist. It should be: aoColumnDefs .
Allan
About that i load my data through a servlet from a database, i just don't want it to be presented in more than one page, since the table (maybe about this there is a misunderstanding, i mean the one in the database), in this particular case, will never be that big to justify pagination.
[quote]allan said: Doesn't exist. It should be: aoColumnDefs .[/quote]
I can't believe i missed that, i checked the whole code hundred of times, my eyes were burning. This solved the issue, thank you very much and congratulation for the great work.
PS. I'm looking forward to be able to bound mData dinamically with the data received from the JSON as if i didn't misunderstand this possibility would be implemented in datatable 1.10.
Allan