fnRender and supplied Data behavior?

fnRender and supplied Data behavior?

AntibrummAntibrumm Posts: 3Questions: 0Answers: 0
edited June 2011 in DataTables 1.8
Hello all
i have a question about the current behavior of the fnRender functionality in this plugin.
Is the current implementation of the call to fnRender with the modified data correct or is this a bug? With each update i'm currently changing it with the feeling that i don't understand why it is currently implemented as it is. Probably someone else can explain me if it's exactly good for him/her?

Currently the fnRender function is called with the aData object which will be modified with each call of fnRender (e.g. the aData contains the result). So my problem is that with this behavior we cannot relay on the data that was processed (rendered) before because the "rawData" of the fnRender changes from call to call.

I'm always having an ID column for example. Now, in the first column where JSON is delivering a plain number i want to render a link based on the ID. In the next column i want to render an image based on this ID too. But in the second column the id value was replaced with a url by the first fnRender.

And this is exactly where i'm always modifing the code of the plugin with each update. Is there a reason why it was implemented like that?

here's the change for 1.8
// line 2681
// FIX: use supplied data and not the rendered one
_fnSetCellData( oSettings, iRow, i, oCol.fnRender( {
"iDataRow": iRow,
"iDataColumn": i,
"aData": aDataSupplied, // dont use aData because it's always modified
"oSettings": oSettings
} ) );


Thanx

Replies

  • rupsrups Posts: 4Questions: 0Answers: 0
    Hi,

    Just a thought, you could try using aoColumnDefs to attach the rendering function only to the ID column and modifying the content of the second column as well as returning the new content for the ID column when the rendering function is called:

    "aoColumnDefs": [ { "aTargets": [ 0 ], "fnRender":renderFunc } ]

    function renderFunc( oObj )
    {
    var ID = oObj.aData[oObj.iDataColumn];
    oObj.aData[1] = image link for ID;
    return URL link for ID;
    }

    Don't know if this will work, completely untested ;) If it works it would remove the need to modify the DataTables code.

    rups
  • AntibrummAntibrumm Posts: 3Questions: 0Answers: 0
    Thanks for the reply.

    I see.. Treat it more like a rowRenderFunction instead of column wise. This should work! And additionally it will be more performant in my cases where we are doing quite some consolidation all over the place! Nice idea. I will try it asap.

    Anti
  • tcgarvintcgarvin Posts: 1Questions: 0Answers: 0
    edited January 2012
    A workaround for this issue that I am now successfully using, is to hide the original data, and have any/all related columns reference that data. DataTables appears to be unaware of a use for this data, so it's left alone.

    For example, my aoColumns looks something like this:

    [code]
    // Here, a column "Client IP" is using d.aData.ip1, which will not
    // be overwritten. (d.aData.sip1 will be overwritten)
    [
    {"mDataProp": "sip1",
    "fnRender": function (d) {
    return pro.util.ipString(d.aData.ip1);
    },
    "sTitle": "Client IP",
    "iDataSort": 6},

    // Here a second column used for sorting is also using
    // d.aData.ip1. (d.aData.iip1 will be overwritten)
    {"mDataProp": "iip1",
    "fnRender": function (d) {
    return pro.util.ipInt(d.aData.ip1);
    },
    "bVisible": false}
    ]
    [/code]
This discussion has been closed.