【问题标题】:Get value of all checkbox selected in jQuery Datatables获取 jQuery Datatables 中选中的所有复选框的值
【发布时间】:2019-10-09 15:15:25
【问题描述】:

我有下一个数据表

HTML

<table id="example" class="row-border hover">
  <thead>
    <tr>
      <th>ID</th>
      <th>Iden.</th>
      <th>Nombres</th>
      <th>Sel.</th>
    </tr>
  </thead>
  <tbody></tbody>
  <tfoot>
    <tr>
      <th>ID</th>
      <th>Iden.</th>
      <th>Nombres</th>
      <th>Sel.</th>
    </tr>
  </tfoot>
</table>

JS

$('#example').DataTable({
    scrollX: true,
    deferRender: true,
    "aaData": data.Data,
    "columns": [{ data: "ID" },
                { data: "Identificacion" },
                { data: "Nombres" },
                { "data"      : null,
                  "targets"   : -1,
                  "orderable" : false,
                  "className" : "all",
                  "width"     : "20px",
                  "render"    : function(data, type, full) {
                                  let texto = "";
                                  texto = '<input type="checkbox" id="check_test" value="' + data.ID + '" />';
                                  return texto;
                              }
                }
               ]
});

我想获取选中复选框的值,所以我尝试了这个

var aux = [];

aux = $('#example tbody input[type=checkbox]:checked').map(function(_, el) {
        return $(el).val();
      }).get();

但是,这只获取从分页数据表的活动页面中选择的值

如何获取datable所有页面选中复选框的值?

【问题讨论】:

  • 你能分享你的分页html输出吗?

标签: javascript jquery datatables


【解决方案1】:

使用$()DataTables API 方法从所有页面检索数据,而不仅仅是第一页。

例如:

var $checkboxes = $('#example').DataTable().$('input[type=checkbox]:checked');

【讨论】:

    猜你喜欢
    • 2017-07-28
    • 2020-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 2014-09-11
    • 2013-01-06
    • 2019-01-05
    相关资源
    最近更新 更多