JQuery DataTables mRender - how to get row id?

With the JQuery DataTables plugin, I use mRender to add buttons to dynamically added rows. This part works fine, but how can I get the rowID of the current row to which the buttons are added? I need this to create unique identifiers for buttons.

What do I need to use instead of ???? in the code below?

JavaScript:

$('#example').dataTable({ "aoColumns": [ { "sTitle": "Person", "mData": "Person" }, { "sTitle": "Buttons", "mData": "Buttons", "mRender": function () { var rowID = ?????; btnD = '<button id="btnDepth' + rowID + '" data-keyindex="' + rowID + '" data-type="Depth" data-action="Show" class="addDepthGraph" title="Show Depth">D</button>'; btnG = '<button id="btnGraph' + rowID + '" data-keyindex="' + rowID + '" data-type="Graph" data-action="Show" class="addDepthGraph" title="Show Graph">G</button>'; var returnButton = btnD + btnG; return returnButton; } } ], "bPaginate": false }); $("#addRowOptions").click(function () { rowindex = $('#example').dataTable().fnGetData().length; obj = [{Person:'PersonA', Buttons: ''}]; $('#example').dataTable().fnAddData(obj); }); 
+4
source share
2 answers

Ok, I found a job. Although this is not an ideal solution, it really works. Now I pass the total number of rows in the grid to the mRender function as the row identifier.

 $('#example').dataTable({ "aoColumns": [ { "sTitle": "Person", "mData": "Person" }, { "sTitle": "Buttons", "mData": "Buttons", "mRender": function (rowIndex) { alert(rowindex); btnD = '<button id="btnDepth' + rowindex + '" data-keyindex="' + rowindex + '" data-type="Depth" data-action="Show" class="addDepthGraph" title="Show Depth">D</button>'; btnG = '<button id="btnGraph' + rowindex + '" data-keyindex="' + rowindex + '" data-type="Graph" data-action="Show" class="addDepthGraph" title="Show Graph">G</button>'; var returnButton = btnD + btnG; return returnButton; } } ], "bPaginate": false }); $("#addRowOptions").click(function () { rowindex = $('#example').dataTable().fnGetData().length; obj = [{Person:'PersonA', Buttons: rowindex}]; $('#example').dataTable().fnAddData(obj); }); 

I would like to know anyway: is it possible to get the current row index from the mRender function? And how to do it?

+3
source

This page has exactly what you need if you use DT_RowId serverside

code:

 "mRender": function ( data, type, full ) { return '<a href="?action=student_report&studentUID='+ full.DT_RowId + '">' + data + '</a>'; 
+3
source

All Articles