Modify data in one column based on data value in another column or columns

Modify data in one column based on data value in another column or columns

rolfsfrolfsf Posts: 27Questions: 6Answers: 0
edited August 2013 in DataTables 1.9
Need a little help - very new to Datatables, and I'm not a programmer..

I want to modify the style (color) of the data in one column based on the value of the data in another column of the same row.

A simple example:
[code]



Foo
Bar




.21 <!-- if this Foo number is less than .25... -->
34 <!-- then this Bar number gets wrapped in a span -->



[/code]

I understand that I want to use mRender, but I don't quite get how to put it all together. I've successfully added a test span based on the following example I found elsewhere in the forums:

[code]
"aoColumnDefs": [
{ "aTargets": [ 1 ],
"mData": "0",
"mRender": function ( data, type, full ) {
return ''+data+'';
}
}
[/code]

but I don't understand what mData: "0" is referring to in this case, and how to get the data from column [0] and evaluate it, before returning the wrapped data for column [1]

can somebody give me a nudge in the right direction?

Thanks!

Replies

  • rolfsfrolfsf Posts: 27Questions: 6Answers: 0
    ok, so I've stumbled into an answer, or at least a partial answer. 'full' is the full array of data for the row (I'm not sure how it differs from 'row'), so I can get the data from a particular column by referring to its index

    for the above example...

    [code]
    "aoColumnDefs": [
    { "aTargets": [ 1 ],
    "mRender": function ( data, type, full ) {
    if(full[0] < 0.25){
    return ''+data+'';
    }else{
    return data;
    }
    }
    ]
    [/code]

    I've run into some issues due to the fact that I have complex headers in the actual table, as well as others, but it's a start
This discussion has been closed.