aoData clobbering aoColumns?

aoData clobbering aoColumns?

cemerickcemerick Posts: 3Questions: 0Answers: 0
edited January 2010 in Bug reports
I was having some trouble getting the fnRender option to work. This was the relevant part of my config:

{aoColumns = [{fnRender: function (obj) {...}} ...]
aoData = [{sName:"foo", ...} ...]}

I had things lined up just as they are indicated in the examples, but my fnRender function was never getting called.

I opened things up in firebug, and noticed that my config object (which I had stored separately) had its aoColumns slot intact before calling .dataTable(config); however, after that invocation, the aoColumns value was identical to the aoData value.

I moved the fnRender slots to the aoData array's maps, and now my rendering functions are being called properly.

It looks like aoColumns gets clobbered by aoData, if the latter is present. This is confirmed by tweaking the config in the column_render.html example to add an empty set of aoData maps:

{
"aoData": [{}{}{}{}{}],
"aoColumns": [
/* Engine */ { "fnRender": function ( oObj ) {
return oObj.aData[0] +' '+ oObj.aData[3];
} },
/* Browser */ null,
/* Platform */ null,
/* Version */ { "bVisible": false },
/* Grade */ { "sClass": "center" }
] } );
}

Further, putting that column configuration under aoData to begin with rather than aoColumns yields perfectly good results.

Looking back at the docs, it makes sense that there should only be one array for column configuration -- some say they should be placed in aoData, others in aoColumns.

Am I doing something wrong here, or are the docs and examples simply wrong (and all column config should just go into aoData)?

Replies

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi cemerick,

    I'm confused - where are you seeing aoData as an initialisation option? aaData can be passed as a 2D array with data ( http://datatables.net/examples/data_sources/js_array.html ), and aoColumns has all the parameters you mentioned: http://datatables.net/usage/columns . And this is an example of fnRender in action: http://datatables.net/examples/advanced_init/column_render.html . But aoData is not an initialisation option.

    There is an internal object called aoData - but unless you are working with the API you probably shouldn't need to use it.

    Allan
  • cemerickcemerick Posts: 3Questions: 0Answers: 0
    Allan,

    Sorry, I should have been more explicit. Check out the example code from http://www.datatables.net/usage/columns for sName and sTitle (there may be other mentions of aoData as a config slot, but those are the two that I'm using).

    - Chas
  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin
    Hi Chas,

    Ah I see - sorry! That's my error in the documentation. Way back in v1.3 I had what is now called aoColumns as aoData - but I decided that was rather a daft name and changed it to something a bit more sensible. In the process I thought I had got all of the documentation updated, but obviously missed a couple of bits... oops - sorry. I've corrected it now. aoColumns is the one to use :-)

    Regards,
    Allan
  • cemerickcemerick Posts: 3Questions: 0Answers: 0
    No worries, thanks for the clarification. All my stuff now uses aoColumns. :-)

    Thanks for datatables, too. It's a great plugin!

    - Chas
This discussion has been closed.