aoColumns works aoColumnsDefs doesn't, can't understand why

aoColumns works aoColumnsDefs doesn't, can't understand why

danieletsdanielets Posts: 11Questions: 0Answers: 0
edited February 2013 in General
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]

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited February 2013
    > `target`

    Is wrong - it should be `aTargets` in DataTables 1.9- ( `targets` will be supported in 1.10+).

    Allan
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    I made that correction and i really hoped it was just that simple to solve the issue, but it seems not.
    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.
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    i still don't manage to get it works, i can't understand what i'm missing
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > "mData": "engine"

    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
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    I tried with 2 different json source.
    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.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    I'm confused - what does your JSON return that you want look like?
  • ender_wiggin30ender_wiggin30 Posts: 7Questions: 0Answers: 0
    I have seen this problem as well. Does debugger send any sensitive information ? I can send my testcase as well if it helps, I am on 1.9.4 with jquery 1.7.2.
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    I'm sorry for my bad english. Forget about the JSON with indexes, it was just a test i made because i didn't know what else to try.

    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.
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    edited February 2013
    The point is that i need to have this infos
    [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)
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    > "version": null

    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
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    edited February 2013
    The error i get is the following:
    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
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited February 2013
    > 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.

    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
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    [quote]allan said: In which case, don't enable server-side processing, since you don't want server-side processing[/quote]

    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.
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Server-side processing does not relate to paging. They are mutually exclusive features - you can have one without the other. If you are returning the full data set, just disable server-side processing since it is useless if you aren't doing the processing at the server.

    Allan
  • danieletsdanielets Posts: 11Questions: 0Answers: 0
    I'm confused. If I disable server-side processing, how would i retrieve data from my database then?
  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    By Ajax. http://datatables.net/release-datatables/examples/data_sources/ajax.html
This discussion has been closed.