【问题标题】:How to add row selection checkbox in data table?如何在数据表中添加行选择复选框?
【发布时间】:2016-12-09 20:37:29
【问题描述】:

您好,我想在数据表中添加行选择 复选框,还需要针对每一行添加复选框。这样它将单独选择行。

谢谢。

【问题讨论】:

标签: php datatables


【解决方案1】:

您可以使用以下代码 JS:

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

HTML

    <table id="example" class="display" cellspacing="0" width="100%">
              <thead>
                <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th>Age</th>
                    <th>Salary</th>
                </tr>
            </thead>
            <tr>
                <td></td>
                <td>Tiger Nixon</td>
                <td>System Architect</td>
                <td>Edinburgh</td>
                <td>61</td>
                <td>$320,800</td>
            </tr>
</table>

【讨论】:

  • 我感觉如果你使用row.add([]),这不会添加复选框
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 2023-03-08
  • 1970-01-01
  • 2015-08-17
  • 2017-03-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多