如何选择所有选中的列,使用jquery DataTables,表的多个复选框,

时间:2018-01-31 10:15:28

标签: jquery datatables

我正在使用带有两列复选框的HTML表格的jquery DataTables。我无法使用标准数据查询" table.columns()。checkboxes.selected()[0];"来检索所有已检查的列。我得到列未定义错误。是因为我使用不同的js,如jquery.dataTables.min.js和dataTables.checkboxes.min.js?

function getSelected(){
        var myTable = $("#myTable").DataTable();

        var selectedIds = myTable.columns().checkboxes.selected()[0];
        console.log(selectedIds)

        selectedIds.forEach(function(selectedId) {
        alert(selectedId);
        });
    }

 <table id="myTable" class="display select">
                    <thead>
                        <tr>
                            <th colspan="2">
                                Notifications
                            </th>                        

                            <th rowspan="3">
                                User ID
                            </th>
                            <th rowspan="3">
                                Last Active (in days)
                            </th>
                            <th rowspan="3">
                                Accepted Jobs
                            </th>
                            <th rowspan="3">
                                Distance (in kms)
                            </th>
                            <th rowspan="3">
                                Job Alert
                            </th>
                            <th rowspan="3">
                                News letter
                            </th>

                        </tr>
                        <tr>
                            <th>
                                JA
                            </th>
                            <th>
                                NL
                            </th>
                        </tr>

                        <tr>
                            <th></th>
                            <th></th>                    
                        </tr>

                    </thead>

                    <tfoot>
                        <tr>
                                <th>Job Alert</th>
                                <th>Newsletter</th>
                                <th>
                                    User ID
                                </th>
                                <th>
                                    Last Active (in days)
                                </th>
                                <th>
                                    Accepted Jobs
                                </th>
                                <th>
                                   Distance (in kms)
                                </th>
                                <th>Job Alert</th>
                                <th>Newsletter</th>
                            </tr>

                    </tfoot>
                    <tbody>
                        <tr>
                            <td> <input class="ja_check">                             
                            </td>
                            <td>  <input class="nl_check">                            
                            </td>
                            <td class="uid" name="uid">
                                100
                            </td>
                            <td>
                                23
                            </td>
                            <td>
                                1000
                            </td>
                            <td>
                                2
                            </td>
                            <td><input class="n_jobalert" id="check" name="check" type="checkbox"><label for="check"><input type="hidden" class="lbljobalert" value="1" /></label></td>

                            <td><input class="n_newsletter" id="check" name="check" type="checkbox"><label for="check"><input type="hidden" class="lblnewsletter" value="0" /></label></td>

                        </tr>
                        <tr>
                            <td>                              
                            </td>
                            <td>                              
                            </td>
                            <td class="uid">
                                102
                            </td>
                            <td>
                                23
                            </td>
                            <td>
                                1000
                            </td>
                            <td>
                                2
                            </td>
                            <td><input class="n_jobalert" id="check" name="check" type="checkbox"><label for="check"><input type="hidden" class="lbljobalert" value="0" /></label></td>

                            <td><input class="n_newsletter" id="check" name="check" type="checkbox"><label for="check"><input type="hidden" class="lblnewsletter" value="1" /></label></td>

                       </tr>



                    </tbody>
                </table>

获取&#34;列未定义&#34;

的错误

0 个答案:

没有答案