下面是我的编码,如果选中复选框,则会选中所有复选框并在第一时间显示记录计数。在第二次,如果我选中复选框我正在计算记录,但复选框被选中 列中的排序图标
JavaScript的:
<script>
$(document).ready(function() {
$('#dataTables-example').DataTable({
responsive : true,
});
$("#selectall").click(function() {
$('.case').attr('checked', this.checked);
if ($('.case').attr('checked', this.checked)) {
count = this.checked ? $(".case").length : 0;
username_Must.innerHTML = count;
}
});
$(".case").click(function() {
count = $(".case:checked").length;
if ($(".case").length == $(".case:checked").length) {
$("#selectall").prop("checked", true);
} else {
$("#selectall").prop("checked", false);
}
username_Must.innerHTML = count;
});
});
</script>
HTML:
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr> <th><input type="checkbox" id="selectall"/></th>
<th>Student Name</th>
<th>Phone</th>
<th>ReferenceId</th>
</tr>
</thead>
<tbody>
<s:iterator value="adminSms">
<tr>
<td><input type="checkbox" class="case" name="case" /></td>
<td><s:property value="studentname" /></td>
<td><s:property value="phone" /></td>
<td><s:property value="ref" /></td>
</tr>
</s:iterator>
</tbody>
</table>
答案 0 :(得分:1)
为数据表添加以下代码。
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
products: DS.hasMany('product')
});
添加&#39; no-sort&#39;要禁用以进行排序的列的类。
$('#dataTables-example').DataTable({
responsive : true,
"aoColumnDefs": [
{"bSortable": false, "aTargets": 'no-sort'},
]
});
我希望这对你有所帮助。
对于复选框计数:
<table width="100%" class="table table-striped table-bordered table-hover"
id="dataTables-example">
<thead>
<tr> <th><input type="checkbox" id="selectall"/></th>
<th class='no-sort'>Student Name</th>
<th>Phone</th>
<th>ReferenceId</th>
</tr>
</thead>
<tbody>
<s:iterator value="adminSms">
<tr>
<td><input type="checkbox" class="case" name="case" /></td>
<td><s:property value="studentname" /></td>
<td><s:property value="phone" /></td>
<td><s:property value="ref" /></td>
</tr>
</s:iterator>
</tbody>
</table>