Data Tables Get iDataRow in mRender

2020-07-30 01:32发布

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?

3条回答
Explosion°爆炸
2楼-- · 2020-07-30 01:33
 "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>";
  }                       
查看更多
趁早两清
3楼-- · 2020-07-30 01:35

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:

  1. fnRender (deprecated)
  2. mRender
  3. 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:

查看更多
姐就是有狂的资本
4楼-- · 2020-07-30 01:53

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

查看更多
登录 后发表回答