В моей форме у меня есть поле выбора с 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: идентификатор таблицы = item_pricelvl -Запрошен неизвестный параметр «6» для строки 0, столбца 6. Для получения дополнительной информации об этой ошибке см. http://datatables.net/tn/4
Ниже я вставляю экран этой страницы Так, если он работает со всеми столбцами, почему я получаю сообщение об ошибке, когда помещаю столбец невидимым?