html 如何在jQuery datatable中获取多个checkbox checked值

sgtfey8w  于 2023-05-05  发布在  jQuery
关注(0)|答案(1)|浏览(242)

单击按钮时,我想从datatables中获取多行选定值。从下面的代码中,我只得到第一行选中的值。

function AssignVendor() {
    var table = $(assignVendor).DataTable();
    var data = table
            .row({ selected: true })
            .data();
}
<table id="assignVender" class="mp myTable table table-striped table-bordered" cellspacing="0" width="100%" ui-jq="dataTable" ui-options="dataTableOpt">

                        <thead>
                            <tr>
                                <th class="select-checkbox"></th>
                                <th>MP Name</th>
                                <th>MP Code</th>
                                <th>Vendor Name</th>
                                <th>Vendor Code</th>
                                <th>From Date</th>
                                <th>To Date</th>
                                <th>Remarks</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="mp in MaintenanceZones">
                                <td></td>
                                <td>{{mp.MP_NAME}}</td>
                                <td>{{mp.MP_CODE}}</td>
                                <td>{{mp.REMARK}}</td>
                                <td>{{mp.VENDORNAME}}</td>
                                <td>{{mp.VENDORCODE}}</td>
                                <td>{{mp.VFRDATE}}</td>
                                <td>{{mp.VTODATE}}</td>

                            </tr>

                        </tbody>
                    </table>

我该怎么解决?

brgchamk

brgchamk1#

试试这个

$('#assignVender').on( 'click', 'tr', function () {
        $(this).toggleClass('selected');
    } );

function AssignVendor() {
    var table = $(assignVendor).DataTable();
    var data = table.rows('.selected').data();
}

参考:https://datatables.net/examples/api/select_row.html
要循环数据,请使用以下命令:

data = table.rows('.selected').data();
data.each( function ( value, index ) {
        console.log( 'Data in index: '+index+' is: '+value );
    } );

相关问题