Access cell datasource from columns.createdCell

Access cell datasource from columns.createdCell

ancashoriaancashoria Posts: 3Questions: 1Answers: 0

Hi, how would I get the cell data source from createdCell callback ?

http://datatables.net/reference/option/columns.createdCell

cellData parameter is the actual text returned by render function, not the cell data source

The row contains the cell data source, but how do I access it ? My row is an object with keys for columns, can I use the column index to access it somehow ?

This question has an accepted answers - jump to answer

Answers

  • ancashoriaancashoria Posts: 3Questions: 1Answers: 0

    To me it would seem natural for cellData to be the actual cell data source, not the text inside the <td>

    The text inside the td is easily accessible with $('td').html() but the cell data source is not

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    To me it would seem natural for cellData to be the actual cell data source, not the text inside the <td>

    Agreed. Let me have a bit of an investigation into why it is the way it is and I'll get back to you on this.

    Allan

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    In the meantime you could use the third parameter and access the data directly. Not ideal, but a workaround.

    Allan

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Answer ✓

    I've gone back on forth on this as having the rendered data can be quite useful, particularly if you need to add a class based on a calculation performed by columns.render. However, I think it is still right to pass in the raw data and I've made the required change and added clarification for this in the documentation. If you do need the rendered string, use $(cell).html().

    Commit

    Thanks for bringing this up!

    Allan

  • ancashoriaancashoria Posts: 3Questions: 1Answers: 0

    Thanks for all the help allan, great work.

This discussion has been closed.