I am getting error in js when I am adding or removing column in controller. As I am getting data in Network, its mean bug is in js code.
Error
enabled:795 Uncaught TypeError: Cannot read properties of undefined (reading 'split') at jquery.dataTables.min.js:18
JS CODE
$(document).ready(function () {
var oTable = $('#dynamic-table').dataTable({
"aaSorting": [[3, "asc"]],
"aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
"iDisplayLength": <?=$settings->rows_per_page;?>,
'bProcessing': true, 'bServerSide': true,
'sAjaxSource': '<?php echo base_url(); ?>panel/customers/getAllCustomers/<?php echo $toggle_type;?>',
'fnServerData': function (sSource, aoData, fnCallback) {
aoData.push({
"name": "<?php echo $this->security->get_csrf_token_name() ?>",
"value": "<?php echo $this->security->get_csrf_hash() ?>"
});
$.ajax({'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback});
},
"aoColumns": [
null,
null,
null,
null,
{mRender: tp},
{mRender: actions},
],
});
});
Controller:
public function getAllCustomers($type = NULL)
{
$this->load->library('datatables');
$this->datatables
// ->where('id !=', 1)
->select('id, CONCAT(first_name, " ", last_name ) as name, company, address, email,
telephone, disable')
->from('clients');
// if ($type === 'disabled') {
// $this->datatables->where('disable', 1);
// } elseif($type === 'enabled') {
$this->datatables->where('disable', 0);
// }
$this->datatables->where('(universal=1 OR store_id='.$this->activeStore.')', NUll, FALSE);
$this->datatables->add_column('actions', "$1___$2", 'id, disable');
$this->datatables->unset_column('id');
$this->datatables->unset_column('disable');
echo $this->datatables->generate();
}