如何解决如果使用 columnDefs 的 dataTable 隐藏特定的列和数据,然后将其隐藏的数据传递给数据库,则它不起作用
我所做的是每行有两个复选框。我有两个复选框的原因是第一个复选框是我的状态,所以我在我的行中使用布尔 (0,1) 第二个复选框是 ID,这样当我更新我的状态时,它会转到特定的 ID。问题是这个。我对 dataTables 不太了解,我研究发现我可以使用 css 隐藏一列并将其配置在 columnDefs 或 aocolumnDefs 中。我所做的是隐藏了 ID 的复选框列,这样它就不会看起来一团糟。所以让我们说我的数据表中有 20 个数据,第 1 页显示 1-10 个数据,然后当我更新这 10 个项目时,可以将它推送到服务器并将数据插入到数据库中,遗憾的是当我尝试更新第二页它显示错误,我的 PHP 中的 $_POST 变量不会读取隐藏的列,它的复选框被选中。我发现第二页无法读取隐藏列。我真的很困惑该怎么做。为了详细说明,我将显示我的问题所在的图像。预先感谢您的帮助!
参考是 >>>> this
这是第二页,它不会将数据的状态更新到数据库,因为它不会从隐藏列中获取值。
我收到的错误
这里没有隐藏我的 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],{
"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 代码
.hide_column {
display: none;
}
解决方法
发现不能在分页期间完成。这是因为分页的限制,例如,如果您有数据 1-10,则仅接受 1-10 数据,而 11....n 之后的数据将被忽略,尽管有任何逻辑。这就是为什么最好为 UI 考虑其他逻辑
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。