I am using DataTables and the TableTools
It is possible get row index in mRender? Something like this:
{
"mData": "someData",
"mRender" : function ( data, type, full ) {
**// get iDataRow somehow**
return '<a href="'+data+'">Download '+ **iDataRow** +'</a>';
}
}
- and not alter data for return of iDataRow
suggestions?
Allan: This feature (columns.render) is available starting from May 2014, DataTable 1.10
release. "...columns.data, columns.render should be able to do
anything fnRender could do".
The evolution chain of the datatable render feature:
- fnRender (deprecated)
- mRender
- columns.render (the latest, most powerful)
Example: columns.render - Use as a function to create a link from the data source.
$('#example').dataTable( {
"columnDefs": [ {
"targets": 0,
"data": "download_link",
"render": function ( data, type, full, meta ) { //meta.row is what you are looking for
var ix = meta.row;
return "Row number is " + ix;
}
} ]
} );
Here are two related unanswered questions from datatable forum, but the first contains the references which helped me to find out the answer:
- How to get row index in mData, June 2013
- Get row index in mRender, December 2012
"mRender": function (data, type, row) {
return "<a href='@Url.Action("Delete", "Review")?id=" + row.ReviewId + "'" + " Class='label label-sm label-success deleteLink loader' >Active</a>";
}
I do not know if you mean you want to get information of certain rows when you mean iDataRow
.
{
"mData": "someData",
"mRender" : function (data, type, full, row) {
// * * get iDataRow somehow**
return '<a href="' + data + '">Download ' + row[0] + '</a>'; // Row[0] = first column first row data
}
}
Good luck with the implementation