【问题标题】:Datatable jquery to limit number of selectable rows to maximum of 5 on checkbox selectDatatable jquery将复选框选择的可选行数限制为最多5个
【发布时间】:2020-11-17 12:26:36
【问题描述】:

我正在使用数据表示例:https://datatables.net/extensions/select/examples/initialisation/checkbox.html 使用复选框选择多行。这工作正常。我可以按住 Ctrl 键选择多行。表格底部显示选定的行数。我遇到的问题是我想阻止用户选择超过 5 行。如何调整 JQUERY 以限制最多选择 5 行,然后阻止用户再选择,除非他们取消选择一行?

var table = $('#tabledt').DataTable({
    columnDefs: [{
        orderable: false,
        className: 'select-checkbox',
        targets: 0
    }],
    select: {
        style: 'os',
        selector: 'td:first-child'
        
    },
    order: [[1, 'asc']]
});

【问题讨论】:

    标签: javascript datatable


    【解决方案1】:
    table.on('select', function (e, dt, type, ix) {
        var selected = dt.rows({ selected: true });
        if (selected.count() > 5) {
            dt.rows(ix).deselect();
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-15
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-05
      相关资源
      最近更新 更多