I am using this datatable server side processing in codeigniter 4 but i found error
DataTables warning: table id=admin_user_datatable - Requested unknown parameter '0' for row 0, column 0. For more information about this error, please see http://datatables.net/tn/4
controller:
public function ajaxDataTables()
{
$users=new UserModel();
$data = array();
$params['draw'] = @$_POST['draw'];
$start = @$_POST['start'];
$length = @$_POST['length'];
$search_value = @$_POST['search']['value'];
if(!empty($search_value)){
$total_count = $this->db->query("SELECT employee_name,employee_email,employee_phone from users WHERE id like '%".$search_value."%' OR employee_name like '%".$search_value."%' OR employee_email like '%".$search_value."%' OR employee_phone like '%".$search_value."%'")->getResult();
$data = $this->$db->query("SELECT employee_name,employee_email,employee_phone from users WHERE id like '%".$search_value."%' OR employee_name like '%".$search_value."%' OR employee_email like '%".$search_value."%' OR employee_phone like '%".$search_value."%' limit $start, $length")->getResult();
}else{
// count all data
$total_count = $this->db->query("SELECT employee_name,employee_email,employee_phone from users")->getResult();
// get per page data
$data = $this->db->query("SELECT employee_name,employee_email,employee_phone from users limit $start, $length")->getResult();
}
$no = @$_POST['start'];
foreach ($data as $employee) {
$no++;
$row = array();
$row[] = $no;
$row[] = $employee->employee_name;
$row[] = $employee->employee_email;
$row[] = $employee->employee_phone;
$row[] ='<a href=""><span class="role member">Update</span></a> || <a href=""><span class="role admin">Delete</span></a>';
$data[] = $row;
}
$json_data = array(
"draw" => @$_POST['draw'],
"recordsTotal" => count($total_count),
"recordsFiltered" => count($total_count),
"data" => $data // total data array
);
echo json_encode($json_data);
}
var site_url = "<?php echo site_url(); ?>"; $(document).ready( function () { $('#admin_user_datatable').DataTable({ paginationType: "full_numbers", lengthMenu: [[ 10, 30, -1], [ 10, 30, "All"]], processing: true, serverSide: true, scrollY: "400px", scrollCollapse: true, ajax: { url: site_url + "/ajax-datatable", // json datasource type: "post", data: { // key1: value1 - in case if we want send data with request } }, columnDefs: [ { orderable: false, targets: [0, 1, 2, 3] } ], // bFilter: true, // to display datatable search }); });