简体   繁体   English

每行上的数据表获取按钮

[英]Datatable get button on each row

I have 2 buttons in each row in a column 'action' in a datatable.我在数据表的“动作”列中的每一行都有 2 个按钮。 Each button on different rows have same class but different data-id.不同行上的每个按钮具有相同的 class 但不同的数据 ID。 I want to click one of the buttons in each row from jquery to simulate button click.我想从 jquery 中单击每一行中的一个按钮来模拟按钮单击。 I am trying to loop over the datatable and get the buttons on each row but failed to get it.我正在尝试遍历数据表并获取每一行上的按钮,但未能得到它。

Please check the ss.请检查ss。

在此处输入图像描述

$('#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?
            } );
        });

You can use the node function .node() function to get the element of the selected row.您可以使用节点function .node() function 来获取所选行的元素。 Then you can wrap it in jQuery to perform jQuery actions on it like this:然后您可以将其包装在 jQuery 中,以对其执行 jQuery 操作,如下所示:

    $('#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
        } );
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM