DataTables warning: table id=admin_user_datatable - Requested unknown parameter '0' for row 0, colum

DataTables warning: table id=admin_user_datatable - Requested unknown parameter '0' for row 0, colum

seema123seema123 Posts: 2Questions: 2Answers: 0
edited January 2022 in DataTables 1.10

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);
}

<script>

    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
        });
    });
  </script>

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • allanallan Posts: 61,450Questions: 1Answers: 10,055 Site admin
    edited January 2022

    Thanks for your question. As noted in the forum rules, please post a link to a running test case showing the issue so we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    If for whatever reason a test case isn't possible, please use the debugger on your page to give me a trace please - click the Upload button and then let me know what the debug code is.

    Thanks,
    Allan

Sign In or Register to comment.