我所做的是每行有两个复选框。我有两个复选框的原因是第一个复选框用于我的状态,因此我在行中使用布尔值 (0,1) 第二个复选框用于 ID,这样当我更新状态时,它将转到特定的 ID。问题是这样的。我对dataTables了解不多,我研究发现我可以使用css隐藏列并在columnDefs或aocolumnDefs内配置它。我所做的就是隐藏了 ID 的复选框列,这样它就不会看起来很混乱。因此,假设我的 dataTable 中有 20 条数据,第一页显示 1-10 条数据,然后当我更新这 10 条数据时,将其推送到服务器并将数据插入数据库时没问题,遗憾的是,当我尝试更新第二页它显示错误,我的 PHP 中的 $_POST 变量不会读取隐藏列,并且它是已选中的复选框。我发现第二页无法读取隐藏列。我真的很困惑该怎么办。为了更详细地说明,我将显示我的问题所在的图像。预先感谢您的帮助!
参考是>>>>this https://stackoverflow.com/questions/14372655/jquery-datatables-hide-column-without-removing-it-from-dom
这是第一页图像,其中数据状态已成功更新到我的数据库(这是第一页)
这是第二页,它不会将数据状态更新到数据库,因为它不会从隐藏列中获取值。
我收到的错误
这是没有隐藏我的 ID 列并且它有效。数据已更新。
我的整个代码
< script >
//For checkboxes to pass the value to database
$(document).ready(function() {
$('.is_checked_status').on('click', function() {
var checkAll = this.checked;
// find the row
var row = $(this).closest("tr");
// find the checkboxes in the row
row.find('input.subCheckbox').each(function() {
this.checked = checkAll;
});
});
});
// Code for dataTable, solution for the bug during ascending and descending
$(document).ready(function() {
$("#dataTables").DataTable({
aaSorting: [
[0, 'asc']
],
bPaginate: true,
bFilter: true,
bInfo: true,
bSortable: true,
bRetrieve: true,
aoColumnDefs: [{
"aTargets": [0],
"bSortable": true
},
{
"aTargets": [1],
"bSortable": true
},
{
"aTargets": [2],
"bSortable": true
}
]
});
// .column(5).visible(false)
});
// Separated this code due to prohibitions by dataTables.net
$('#dataTables').DataTable({
aoColumnDefs: [{
aTargets: [5],
"sClass": "hide_column"
}]
}); <
/script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Emailed Data for approval
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables">
<thead>
<tr>
<th> Control Number </th>
<th> Tools Specification </th>
<th> Supplier </th>
<th>
<center> Status </center>
</th>
<th>
<center> Select data to approve </center>
</th>
<th>
<center> ID </center>
</th>
</tr>
</thead>
<?php
$con->next_result();
$result = mysqli_query($con,"CALL GetAllRequestedTools()"); ?>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td><a href='edit_tools_approval.php?ID=".$row['ID']."'
style='color:red;'>" . $row['reg_input'] . "</a></td>";
echo "<td>" . $row['reg_tools_spec'] . "</td>";
echo "<td>" . $row['reg_supplier'] . "</td>";
?>
<td>
<center>
<label data-id="<?php echo $row['ID'];?>" class="statusButton <?php echo
($row['req_stats'])? 'label-success': 'label-danger'?>">
<?php echo ($row['req_stats'])? 'Approved' : 'Pending'?>
</label>
</center>
</td>
<td>
<center>
<input name="chk_status[]" class="is_checked_status" type="checkbox" value="
<?php echo $row['req_stats'];?>">
</center>
</td>
<td class="hide_me">
<center>
<input name="chk_id[]" type="checkbox" class="subCheckbox" value="<?php echo
$row['tools_req_id'];?>">
</center>
</td>
<?php
echo "</tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="col-lg-15">
<div class="form-group">
<button type="button" id="submitBtn" class="btn btn-success pull-
right" data-toggle="modal" data-target="#myModal">
<span class="fa fa-check"></span>
Update
</button>
</div>
<div class="form-group">
<button type="button" id="submitBtn" class="btn btn-danger pull-
right" data-toggle="modal" data-target="#cancelModal">
<span class="fa fa-times"></span>
Cancel
</button>
</div>
</div>
</div>
</div>
CSS code
.hide_column {
display: none;
}
发现分页期间无法完成此操作。这是因为分页的限制,例如,如果您有数据 1-10,则仅接受 1-10 数据,而 11....n 以后的数据将被忽略,无论任何逻辑。这就是为什么最好为 UI 考虑其他逻辑
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)