.node() is undefined

.node() is undefined

apancuapancu Posts: 6Questions: 0Answers: 0

When DT2 render function is called with type == 'display' the node() is undefined. Is this by design? It makes it difficult to access the DOM for the current cell. In DT1 it was available. deferRender is set to false.

Replies

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954
    edited May 2

    Can you post your code snippet so we can see what you are trying to do?

    The columns.render docs state this:

    Render (process) the data for use in the table.

    It is intended to operate on the data not the DOM node. createdRow, rowCallback and columns.createdCell are the expected functions to access and alter the DOM node. Possibly you can use one of those callbacks instead.

    Kevin

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    I'm sure there was another thread on this topic recently, but can I find it now... Not a chance!

    No - I don't recall intentionally making that change, but it probably happened due to changes in this area. As Kevin notes, it isn't really expected that you would get the node in a rendering function, and you certainly wouldn't want to use the API to get it due to the overhead.

    A test case would be really useful.

    Allan

  • apancuapancu Posts: 6Questions: 0Answers: 0

    Thanks for the quick responses. Yes, that was me in another discussion here:
    https://datatables.net/forums/discussion/comment/231353#Comment_231353

    I am currently trying to use createdRow instead. I need to conditionally set a class on a cell based on it's data and the column definition. The table data is server side and reloaded every second.

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    Ah yes, and in the PM - apologies I lost track of that. Too much going on :).

    I've created this little example to show the issue.

    I need to conditionally set a class on a cell based on it's data and the column definition.

    columns.createdCell might be your best option. Example here: https://live.datatables.net/kacufezo/1/edit .

    That will be far more performant than using the API in the rendering function.

    Allan

  • apancuapancu Posts: 6Questions: 0Answers: 0

    Awesome! Thanks again, Allan. I will try that at once.

    Thanks,
    Andrei

Sign In or Register to comment.