get 'rendered' data from row api.
get 'rendered' data from row api.

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?
This discussion has been closed.
Replies
Use
cell().render()
to get the rendered data (edit andcells().render()
for multiple cells - i.e. a row or a column).Allan
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?
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
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.
Found that
table.cells( rowSelector, null ).render( 'display' )
doesn't work.null
needs to be replaced with''
as shown in thecells().render()
docs. For example:table.cells( rowSelector, '' ).render( 'display' )
Kevin