简体   繁体   中英

How to get multiple checkbox checked value in jquery datatable

On Button Click, I want to get the multiple row selected value from the datatables . From my below code, I only get the first row selected value.

 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> 

Please help

Try this

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

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

Reference: https://datatables.net/examples/api/select_row.html

To Loop through the data use the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM