Somil Aseeja
Somil Aseeja

Reputation: 170

Datatable get button on each row

I have 2 buttons in each row in a column 'action' in a datatable. Each button on different rows have same class but different data-id. I want to click one of the buttons in each row from jquery to simulate button click. I am trying to loop over the datatable and get the buttons on each row but failed to get it.

Please check the ss.

enter image description here

$('#apply-all').on('click', function (e) {
            var table  = $('.mydatatable').DataTable();
            table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
                  var data = this.data(); // able to fetch the data.
                  //how to feth the button on this row?
            } );
        });

Upvotes: 1

Views: 1670

Answers (1)

gaganshera
gaganshera

Reputation: 2639

You can use the node function .node() function to get the element of the selected row. Then you can wrap it in jQuery to perform jQuery actions on it like this:

    $('#apply-all').on('click', function (e) {
        var table  = $('.mydatatable').DataTable();
        table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
              var data = this.data(); // able to fetch the data.
              var row = this.node();
              var rowJqueryObject = $(row);
              //or
              $(row).find('button'); //will return all buttons in that row
        } );
    });

Upvotes: 2

Related Questions