【问题标题】:Datatable get button on each row每行上的数据表获取按钮
【发布时间】:2020-05-11 07:16:56
【问题描述】:

我在数据表中的“操作”列的每一行中有 2 个按钮。不同行上的每个按钮具有相同的类但不同的数据 ID。我想单击 jquery 中每一行中的一个按钮来模拟按钮单击。我正在尝试遍历数据表并获取每一行的按钮,但未能获取。

请检查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?
            } );
        });

【问题讨论】:

  • 能分享一下HTML代码吗?

标签: javascript html jquery dom datatable


【解决方案1】:

您可以使用node 函数.node() 函数来获取所选行的元素。然后你可以将它包装在 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
        } );
    });

【讨论】:

  • 谢谢 gaganshera,我也会检查一下。我有一个问题,我在数据表中有 25 个视图,当我获得表实例时,我只得到 25 个计数,而数据超过 25 个。
  • 表实例是什么意思?
  • var table = $('.mydatatable').DataTable();
  • 当我在做的时候: var buttons = $(row).find('button');按钮[0].click();它只单击第一行中的按钮而不是其他按钮。并且按钮单击事件会进行 ajax 调用。
  • button[0] 指定它找到的第一个按钮
猜你喜欢
  • 2023-03-06
  • 2016-01-15
  • 1970-01-01
  • 2014-04-23
  • 2013-02-23
  • 1970-01-01
  • 2017-06-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多