javascript - 隐藏列后数据表中出现错误
问题描述
在我的表单中,我有一个带有 2 个选项的选择框:当您选择其中一个时,我的 DataTable 必须更改他的列:
//Changing TYpe of Price level will change datatable
$('#price_method').on("change", function(){
//Declare the variable
var oTable=$('#item_pricelvl').DataTable();
oTable.clear();
//Destroying the table and then rebuilding it again
oTable.destroy();
//If Selected Price Override
if ($(this).val()=="PO"){
//I gotta hide a column
$('#item_pricelvl').DataTable({
"columnDefs":[
{
"class":"details-control",
},
{
"targets":['_all'],
"orderable":false
},
//I'm hiding the 4th column
{ "visible": false, "targets": 4 },
"Column"
],
})
}else{ //Else I can show all columns
$('#item_pricelvl').DataTable({
"columnDefs":[
{
"class":"details-control",
},
{
"targets":['_all'],
"orderable":false
},
"Column"
],
})
}
});
//INSERT NEW PRICE LEVEL INTO THE ITEM PRICE TABLE
$('#insertplvl').click(function(){
//Checking what method is selected
if ($('#price_method').val()=="CM"){
//starting to add the new row into the DataTable, and No columns hiding
it_det.row.add([
"D",
"COST MARKUP",
"1",
"999999999",
"0.00",
"0.00",
"<input type='checkbox' name='chkdet' class='chk_plvl' id='"+ct_row+"'/>"
]).draw(false);
}else{
//starting to add the new row into the DataTable, and adding just 6 values because of the hide column
it_det.row.add([
"D",
"PRICE OVERRIDE",
"1",
"999999999",
"0.00",
"<input type='checkbox' name='chkdet' class='chk_plvl' id='"+ct_row+"'/>"
]).draw(false);
}
//Increasing the counter
ct_row++;
})
<table id="item_pricelvl" class="table table-bordered table-striped">
<thead>
<tr>
<th>Price Level</th>
<th>Pricing Method</th>
<th>From Quantity</th>
<th>To Quantity</th>
<th>Markup Amount</th>
<th>Unit Price</th>
<th><input type="checkbox" class="checkall" /></th>
</tr>
</thead>
</table>
当我尝试插入选择“POP”时,出现此错误:
DataTables 警告:表 id=item_pricelvl - 请求第 0 行第 6 列的未知参数“6”。有关此错误的更多信息,请参阅http://datatables.net/tn/4
解决方案
推荐阅读
- r - 过滤跨多年数据集的特定日期范围
- javascript - 在 react.js 中创建图像之前,是否有替代使用 import 或 require 语句的方法。使用 jango、react 和 webpack
- python - 如何正确解析带有重复键的 JSON 文件?
- three.js - THREE.BoxBufferGeometry 与 raycaster.intersectObjects 相交
- c - 二叉搜索树中的搜索元素
- autodesk-forge - 调整图像大小时,带有标记的屏幕截图无法正常工作
- python - 从包装类推断类型注释
- assembly - 汇编文件错误
- xml - 詹金斯情节是空的
- python - 具有数据类属性的必需位置参数