dataTables添加序号和行选中框

 1 <table id="mytable" class="table table-striped table-bordered" width="100%">
 2     <thead>
 3         <tr>
 4                 <th>序号</th>
 5                <th>
 6                     <input type="checkbox" class="checkall" />
 7                 </th> 
 8             </tr>
 9     </thead>
10    <tbody></tbody>
11 </table>
 1 $(document).ready(function(){
 2     var table = $("#mytable").DataTable({
 3             "processing":true,
 4              "ajax": {
 5                  "url": "user/getTableDatas",
 6              },
 7              "columns": [
 8                 {"data":"index",//序号
 9            "render":function(data,type,row,meta){
10             var startIndex = meta.settings._iDisplayStart;
11             return startIndex+meta.row+1;
12         }},
13                 {
14                     "sClass": "text-center",
15                     "data": "id",//行单选框
16                     "render": function (data, type, full, meta) {
17                       return '<input id="checkchild" type="checkbox"  class="checkchild"  value="' + data + '" />';
18                     },
19                     "bSortable": false
20                 }  
21              ],
22              //行被创建时调用
23              "createdRow":function(row,data,dataIndex){
24                  
25              }
26     });
27     //复选框全选
28     $(".checkall").click(function () {
29           var check = $(this).prop("checked");
30           $(".checkchild").prop("checked", check);
31           checkButton();
32     });
33     //行内的选择框选中
34     $(document).on("click","#checkchild",function(){
35         var check = $(this).prop("checked");
36         if(check && check==true){
37             $(this).prop("checked",false);
38         }else{
39             $(this).prop("checked",true);
40         }
41         checkButton();
42     });
43 
44     //选中行事件
45     $("#mytable tbody").on("click","tr",function(){
46         var check = $(this).find(".checkchild").prop("checked");
47         if(check && check==true){
48             $(this).find('.checkchild').prop("checked",false);
49         }else{
50             $(this).find('.checkchild').prop("checked",true);
51         }
52         checkButton();
53       
54     });

 

转载于:https://www.cnblogs.com/suruozhong/p/6256515.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值