如何在数据表中添加行选择复选框?

3

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

谢谢。


不清楚你的工作环境、使用的编程语言和框架是什么? - vels4j
我正在使用PHP框架工作,并且我已经添加了datatable以显示来自数据库的结果。 - Hemant
请查看以下链接:http://stackoverflow.com/questions/17671815/how-can-i-add-a-check-box-to-a-data-table-to-be-used-to-delete-the-selected-rowhttp://stackoverflow.com/questions/10794430/update-database-table-with-checkboxes-php-mysql - vels4j
谢谢,我会检查的。 - Hemant
1个回答

3
您可以使用以下代码 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([]),它不会添加复选框。 - Zac Grierson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接