panchtox
panchtox

Reputation: 642

Get datatable id on click

I have several datatables in shiny and I want to get the id from any clicked table using callback property. I've tried several ways but it doesn't work. I've used this code:

DT::renderDataTable({
        DT::datatable(
          v$data, editable = list(target = "cell", disable = list(columns = disabled_cols)), options = list(bPaginate=F,bFilter=F),selection = "none",
          callback = JS("table.on('click.dt', 'td', function() {
            var row_=table.cell(this).index().row;
            var col=table.cell(this).index().column;
            var id= table.id;
            var data = [row_, col, id];
           Shiny.onInputChange('rows',data );
    });")
                      )
        
      })

and several other options instead "table.id" in order to obtain the ID of the table on click. It works to obtain row and col number, but I don't figure out how to obtain ID.

Upvotes: 0

Views: 1157

Answers (1)

Stéphane Laurent
Stéphane Laurent

Reputation: 84519

Use:

var id = $(table.table().node()).closest('.datatables').attr('id');

Upvotes: 2

Related Questions