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
rolfsf
Posts: 27Questions: 6Answers: 0
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!
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!
This discussion has been closed.
Replies
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