jquery+database+icheck
最近研究表格,研究jquery+database+icheck.
icheck:是raido和checkbox的美化插件。官方地址:http://www.bootcss.com/p/icheck/
可以接口定义单选和多选框的样式。

具体使用可以查看官网例子。

通过icheck 和database实现表格当前页的全选。
html代码:
1 table id="datatable-checkbox" class="table table-striped table-bordered bulk_action "> 2 <thead> 3 <tr> 4 <th> 5 <input type="checkbox" id="check-all" class="flat" > 6 </th> 7 <th>Name</th> 8 <th>Position</th> 9 <th>Office</th> 10 <th>Age</th> 11 <th>Start date</th> 12 <th>Salary</th> 13 <th>Salary</th> 14 <th>操作</th> 15 </tr> 16 </thead> 17 18 <tbody> 19 <tr class="even pointer"> 20 <td class="a-center "> 21 <input type="checkbox" class="flat" name="table_records"> 22 </td> 23 <td class=" ">121000040</td> 24 <td class=" ">May 23, 2014 11:47:56 PM </td> 25 <td class=" ">121000210 <i class="success fa fa-long-arrow-up"></i></td> 26 <td class=" ">John Blank L</td> 27 <td class=" ">Paid</td> 28 <td class="a-right a-right ">$7.45</td> 29 <td class=" last"><a href="#">View</a> 30 </td> 31 <td class=" last"><button class="btn btn-success" href="#">操作</button> 32 </td> 33 </tr><tr class="even pointer">
css:
<link href="/static/css/buttons.bootstrap.css" rel="stylesheet"> <link href="/static/css/dataTables.bootstrap.css" rel="stylesheet"> <link href="/static/css/green.css" rel="stylesheet">
js:
<script src="/static/js/jquery.min.js"></script> <script src="/static/js/icheck.js"></script> <script src="/static/js/jquery.dataTables.min.js"></script> <script src="/static/js/dataTables.bootstrap.js"></script> <script src="/static/js/dataTables.buttons.min.js"></script> <script src="/static/js/buttons.bootstrap.min.js"></script> <script src="/static/js/custom.js"></script>
这里需要注意的是:
因为database不是刷新请求页面,这样的话,在请求第二页的时候出现多选框样式问题。如下是解决方法:
1 $('.a-center').iCheck({ 2 handle: 'checkbox', 3 checkboxClass: 'icheckbox_flat-green' 4 });
需要注意的是:.a-center的 class的位置!!网上解决方案:https://stackoverflow.com/questions/21637458/datatables-icheck-pagination
如果用icheck的话,有个问题:database其他插件无法使用。暂时未找到解决方案。
学习是一种态度,坚持是质变的利器!

浙公网安备 33010602011771号