How define onclick in cells

How define onclick in cells

phawellphawell Posts: 28Questions: 12Answers: 1

If I load all data from server as a JSON and in client the datatable create the table and all the html
how can I set an onclick in every cell of that table? Because the html became created and I have no control

So what I need is create in every td in the data table tags modifiers like

<td data-1=1 data-2=d >cell content string</td>

And if a user click on that cell call a funtion and pass as parametrrs data-1 and data-2 values assigned in that cell

Is that possible? Is there other way to do same functionality

Answers

  • DesconhecidoDesconhecido Posts: 11Questions: 5Answers: 0

    $('#example tbody').on('dblclick', 'td', function () {
    var tr = $(this).closest('tr');
    var row = table.row( tr );
    console.log(row.data());
    } );

    this will console log all row columns when you dbl click any row cell.

    perhaps you can place data1 and data2 as hidden columns on the table then call them in your function

    function_you_want(row.data().data1, row.data().data2).

This discussion has been closed.