get 'rendered' data from row api.

get 'rendered' data from row api.

Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

Hello,

I'm using the row api to grab the row data for display in a drop-down box.
Like when you click on a row and it expands to display more data.

The following works fine in an 'on click' event handler:

   var tr = $(this).closest('tr');
   var row = table.row( tr );
   row.child( expand(row.data()) ).show();

The problem is, row.data() returns the raw data. Since I went to the trouble of applying rendering functions to the data when the DataTable was defined, I'd like to simply pass my already formatted data to the expand function.

Is there an easy way to do this?

Replies

  • allanallan Posts: 62,305Questions: 1Answers: 10,220 Site admin
    edited March 2016

    Use cell().render() to get the rendered data (edit and cells().render() for multiple cells - i.e. a row or a column).

    Allan

  • Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

    Thanks Allan,!

    That's a good start, although the row.data() api call returns an object that is easy to reference. Is there a way to get an object with the rendered data?

  • allanallan Posts: 62,305Questions: 1Answers: 10,220 Site admin

    The cells().render() method I suggested will do that. Just use: table.cells( rowSelector, null ).render( 'display' ) to get the rendered data for the row.

    Or are you looking to get an object back rather than an array? There is no option to get an object back since the data mapping might not be 1:1. I don't think there would be a reliable way to do that - it needs to be column based.

    Regards,
    Allan

  • Dan CarrollDan Carroll Posts: 12Questions: 3Answers: 0

    Thanks again Allan. Yes, an object with named properties is what I was after.
    That's OK, I'll use it as an array. I was trying to avoid problems if I changed the data structure of the table.

    I think I'm doing it the wrong way by creating a new sub-table with javascript. I'll re-think my display code.

  • kthorngrenkthorngren Posts: 20,631Questions: 26Answers: 4,834

    Found that table.cells( rowSelector, null ).render( 'display' ) doesn't work. null needs to be replaced with '' as shown in the cells().render() docs. For example:
    table.cells( rowSelector, '' ).render( 'display' )

    Kevin

This discussion has been closed.