explanation and example of mRender to change styles?
explanation and example of mRender to change styles?
Mike_Mike
Posts: 6Questions: 1Answers: 0
I have some questions about mRender. http://datatables.net/ref#mRender It looks useful to modify the value of a TD, but can it change the style?
I am using aoColumns with fnCreatedCell to format like this:
[code]
oTable = $('#Table2').dataTable( {
"sAjaxSource": "PHP/getdata.php",
"bAutoWidth": false,
"sScrollY": tableheight+"px",
"bPaginate": false,
"bScrollCollapse": false,
"bDestroy": true,
"bFilter": false,
"aoColumns": [
.....
{"sWidth": "50px","sClass": "center mysmall","sDefaultContent": " ",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
if ( sData == "BELOW MIN") {
$(nTd).css('color', 'red');
}
else {$(nTd).css('color', 'black');}
}
}
]
[/code]
then, later I am using fnUpdate to update the value:
[code]
oTable.fnUpdate("BIGGER THAN MIN",aPos,5,false,false);
[/code]
I would ideally like the fnCreatedCell to fire at both creation and after fnUpdate, and it sounds like mRender will do that?
I have been working with DataTables for several months now, and it is great, but the documentation on mRender has literally begun hurting my brain.
I thought I was pretty smart, but this line below from the mRender documentation is absolutely confusing me and I have had no luck finding an example of what this parameter is used for or how the various values are used, or an example of how mRender can change a style of a TD.
[quote] {string} The type call data requested - this will be 'filter', 'display', 'type' or 'sort'. [/quote]
The "type call data requested" can be a value of type? I am confused. what is a "type call data" ?
Very simply, I would like the TD text to be red if the value == "BELOW MIN" and black any other time, and for that to color itself after an update. Sounds simple, right? I am fine with adding/remove a class instead of using .css but I think that is irrelevant to my question.
Thanks,
I am using aoColumns with fnCreatedCell to format like this:
[code]
oTable = $('#Table2').dataTable( {
"sAjaxSource": "PHP/getdata.php",
"bAutoWidth": false,
"sScrollY": tableheight+"px",
"bPaginate": false,
"bScrollCollapse": false,
"bDestroy": true,
"bFilter": false,
"aoColumns": [
.....
{"sWidth": "50px","sClass": "center mysmall","sDefaultContent": " ",
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
if ( sData == "BELOW MIN") {
$(nTd).css('color', 'red');
}
else {$(nTd).css('color', 'black');}
}
}
]
[/code]
then, later I am using fnUpdate to update the value:
[code]
oTable.fnUpdate("BIGGER THAN MIN",aPos,5,false,false);
[/code]
I would ideally like the fnCreatedCell to fire at both creation and after fnUpdate, and it sounds like mRender will do that?
I have been working with DataTables for several months now, and it is great, but the documentation on mRender has literally begun hurting my brain.
I thought I was pretty smart, but this line below from the mRender documentation is absolutely confusing me and I have had no luck finding an example of what this parameter is used for or how the various values are used, or an example of how mRender can change a style of a TD.
[quote] {string} The type call data requested - this will be 'filter', 'display', 'type' or 'sort'. [/quote]
The "type call data requested" can be a value of type? I am confused. what is a "type call data" ?
Very simply, I would like the TD text to be red if the value == "BELOW MIN" and black any other time, and for that to color itself after an update. Sounds simple, right? I am fine with adding/remove a class instead of using .css but I think that is irrelevant to my question.
Thanks,
This discussion has been closed.
Replies
[code]
if ( newdata == "BELOW MIN") {
$(nTr).children().eq(4).css('color', 'red');
}
else {$(nTr).children().eq(4).css('color', 'black');}
[/code]
So for now, I've put in a solution, but my question about mRender and it's documentation still stands. Can it be used to change a style? If so, is there an example? I would like to have all my conditional style code in one place, ideally as part of, or as close to the dataTable definition as possible, so that no matter where I call an fnUpdate from, I know the same style code will be run on it, instead of trying to remember to add the style code after each fnUpdate. Thanks again.
No - its the content of the cell only - it does not have access to the cell node. You can use fnCreatedCell for manipulating the cell.
Allan