【发布时间】:2018-04-10 04:42:14
【问题描述】:
我正在使用数据表来创建一个可排序、可搜索和分页的表,表中的行是加载服务器端的,我为每一行添加一个复选框,并在表头中选中所有复选框,我编写了一个自定义 jquery检查复选框所有行的功能,这是我的代码:
// checkbox check all
$(".checkboxParent").change(function () {
var chkGroup = $(this).data("chk-group");
if (chkGroup !== null) {
$(".checkboxItem[data-chk-group='"+chkGroup+"']").prop('checked', $(this).prop("checked"));
}
else {
$(".checkboxItem").prop('checked', $(this).prop("checked"));
}
});
因为我可能在一页中有多个表,所以需要选中所有复选框,所以我在复选框中包含一个 data-chk-group 字段来标识复选框要检查的组。
问题是我的自定义检查所有功能无法检查数据表插件中行的第二页,有什么方法可以解决这个问题吗??
这是我的 HTML 代码:
<table class="paginateTable table table-hover display pb-30">
<thead>
<tr>
<th class="noSort fit">
<div class="checkbox checkbox-primary">
{!! Form::checkbox('userId', null, null, ['class' => 'checkboxParent', "data-chk-group" => ""]) !!}
<label></label>
</div>
</th>
<th>Level</th>
<th>Name</th>
<th>Members</th>
<th>Gift Point</th>
<th>Wallet</th>
<th>Withdrawal Wallet</th>
</tr>
</thead>
<tbody>
@for ($i=0; $i < 100; $i++)
<tr>
<td>
<div class="checkbox checkbox-primary">
{!! Form::checkbox('userId', null, null, ['class' => 'checkboxItem', "data-chk-group" => ""]) !!}
<label></label>
</div>
</td>
<td>
@php
$userLevel = $levels[rand(0, 3)];
@endphp
<div style="display:none;">
{{$userLevel}}
</div>
<div class="tableImage">
<img src="{{asset($userLevel)}}" alt="">
</div>
</td>
<td>
<span>
<span class="fontWeight800 colorBlack">Fullname {{$i}}</span>
<br>
<span>Username {{$i}}</span>
</span>
</td>
<td>{{$i}}</td>
<td>{{$i * 5}} aP</td>
<td>{{(($i+1) * 10) - rand(1, 5)}} aP</td>
<td>{{(($i+1) * 10) - rand(1, 5)}} aP</td>
</tr>
@endfor
</tbody>
</table>
【问题讨论】: