how to reference the TD when using mRender

how to reference the TD when using mRender

keirlav87keirlav87 Posts: 11Questions: 0Answers: 0
edited October 2012 in General
When using mRender as a function callback, how do you reference the TD that the cell will correspond to - for example if I did

[code]
"mRender": function(data,type,full) {
if( full.team_colour == 'green' )
{
$(this).parents('td').css('background-color','green');
}
return data;
}
[/code]

but obviously that doesn't work or I wouldnt be posting here :P Just hope it makes it clear what i am trying to do?

Replies

  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    > how do you reference the TD that the cell will correspond to

    You don't - mRender is a text rendering method only and not suitable for working with the DOM. If you want to manipulate DOM elements then there is fnCreatedCell .

    Not yet quite happy with the interaction, but I want to keep the DOM nodes away from mRender since deferred rendering can mean the DOM nodes don't exist when the rendering function is called.

    Allan
  • mcevikcemcevikce Posts: 4Questions: 1Answers: 0
    fnCreatedCell works when table loads the data first time. In my case I am using Editable datatable. Users are entering data directly to table cells. I want these numbers automatically formatted using numberformatter. Only way I can think of is to implement formatting logic in mRender. But
    $(nTd).parseNumber({format:"#,###.00", locale:"us"}); wont work unless I have access to TD.
  • allanallan Posts: 63,531Questions: 1Answers: 10,475 Site admin
    You could use mRender as a function and simply return the parsed number could you not? It doesn't actually require the DOM element to be available, it can do string manipulation as well I presume (since the DOM interaction is just an additional part to that).

    Allan
This discussion has been closed.