Get selected row's index in column renderer

Get selected row's index in column renderer

NoBullManNoBullMan Posts: 58Questions: 16Answers: 2

Link to test case:
Debugger code (
Error messages shown:
Description of problem:
I am trying to store selected row's index and retrieve it later. I can get the index using:

var table = $('#example').DataTable();

$('#example tbody').on( 'click', 'tr', function () {
    someVar = table.row( this ).index();
} );

However, it seems if I have a renderer defined for a column that makes the cell data into a link, clicking on the link does not cause the above event to fire.

I thought maybe I can pass row index in renderer function as an alternate method of getting row index; not sure if it is possible.
For example, is it possible to pass row index in setAreaSelection function below?

columns: [ 
        data: "SOME_ID",
        render: function (data, type, row) {
            var cellContent = '';

            if (null != data && '' != data) {
                cellContent += "<a href='javascript:' onclick=\"setAreaSelection('" + data + "')\">" + data + "</a>";
            else {
                cellContent += "0";
            return cellContent;
    }, {
        data: "COUNT"

I also tried accessing selected row in setAreaSelection function itself but nothing is returned because of issue listed on top of the post:

function setAreaSelection(data){
    rows = table.rows('.selected').indexes();

This question has an accepted answers - jump to answer


Sign In or Register to comment.