Undocumented breaking change?

Undocumented breaking change?

procentprocent Posts: 2Questions: 0Answers: 0
edited April 2011 in Bug reports
Hi,
I'm not sure if this post should go under "bug reports", but anyway..
I think I found a breaking change (1.6 - 1.7) that is not documented on upgrading page.
Source code from v1.7.6, line 2650:

[code]
/* Cast everything as a string - so we can treat everything equally when sorting */
if ( typeof aData[i] != 'string' )
{
aData[i] += "";
}
aData[i] = $.trim(aData[i]);
[/code]

This was not present in v1.6. I return a more complex structre from my server, each of the objects additionaly has JSON children array. I put it in hidden column and use it for master/details views, rendering another table from this JSON. The code above causes my JSON to be changed into "[object Object]" string.
Is there any way (except modifying the code manually) to revert previous behavior? Or maybe I can accomplish this some other way?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Heh - funny that this hasn't come up since 1.7.0 and now two in two days ( http://datatables.net/forums/comments.php?DiscussionID=4686 ). It's like buses ;-)

    Yup I think this is a perfectly valid question and a good one at that. My reasoning for doing what I did with 1.7 was that DataTables was expecting display only data returned from the server. You can't display an object, or boolean or whatever (well you can of course, but there are a million ways to interpret the types). As such DataTables currently only really deals with display data (even handling null is questionable...) - hence the cast to a string (it makes some other operations easier).

    However, I completely realise that this is fairly limiting and passing about objects and arrays would be very useful. I plan to make this a lot easier in DataTables 1.8. I'm wrapping up a different feature for 1.8 just now and then will get started on that.

    Regards,
    Allan
  • procentprocent Posts: 2Questions: 0Answers: 0
    Hi Allan,
    Thanks for your response. The JSON object plugin you suggested in the other thread does not do the trick here (actually i already implemented such logic myself before).

    I ended up using fnRender for this column:

    [code]
    aoColumnDefs: [
    {
    aTargets: [7], bVisible: false, fnRender: function (oObj) {
    return JSON.stringify(oObj.aData[7]);
    }
    [/code]

    Then in rowCallback i simply parse it back:
    [code]
    fnRowCallback: function (nRow, aData, iDisplayIndex) {
    var parsed = JSON.parse(aData[7]);
    //...
    [/code]

    It's acceptable here, because child objects array will have max 5-6 elements, and I set page size 15 on parent table - performance won't be an issue. However I can't wait how this will be resolved in 1.8:)

    Thanks for the great work,
    Maciej Aniserowicz
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Hi Maciej,

    Thanks for the feedback - good to hear that you have a work around for now.

    I'm of the opinion that non-display information such as objects shouldn't really be stored in the table itself since that should be for display only, but rather in the DataTable's data store - which is what I plan to do. I use this kind of thing a fair amount myself, so I'm quite looking forward to it as well :-)

    Regards,
    Allan
This discussion has been closed.