Codeigniter Ajax Datatable showing Error -
i have referred link make codeigniter datatable ajax based datatable.
http://mbahcoding.com/tutorial/php/codeigniter/codeigniter-simple-server-side-datatable-example.html
but showing error , not showing data in datatable.
message: undefined index: length
message: undefined index: start
message: undefined index: draw
please me remove these errors.
my jquery
$(document).ready(function(){ //ajax datatable //datatables var datatable = $('#datatables-suburb').datatable({ processing: true, //feature control processing indicator. serverside: true, //feature control datatables' server-side processing mode. order: [], //initial no order. // load data table's content ajax source ajax: { url: "<?php echo site_url('admin/states/state_table_ajax')?>", type: "post" }, //set column definition initialisation properties. columndefs: [ { targets: [ 0 ], //first column / numbering column orderable: false, //set not orderable }, ], }); });
my controller function
public function state_table_ajax() { $data['details'] = $this->loginmodel->admin_details($this->session->userdata('admin-username')); foreach($data['details'] $detail): $country_id = $detail['country_id']; endforeach; $states = $this->statesmodel->get_states_table($country_id); $no = $_post['start']; foreach($states $state): $no++; $row = array(); $row[] = $no; $row[] = $state['id']; $row[] = $state['state_name']; //$row[] = '<button type="button" name="update" id="'.$state['id'].'" class="btn btn-warning btn-xs">update</button>'; //$row[] = '<button type="button" name="delete" id="'.$state['id'].'" class="btn btn-danger btn-xs">delete</button>'; $state_data[] = $row; endforeach; $output = array( "draw" => $_post['draw'], "recordstotal" => $this->statesmodel->get_states_count($country_id), "recordsfiltered" => $this->statesmodel->get_states_count_filtered($country_id), "data" => $state_data, ); //echo "<pre>"; //print_r($output); //output json format echo json_encode($output); }
my model code
public function get_states($country_id) { $order_column = array('id', 'state_name'); $this->db->select('id, state_name') ->where('country_id', $country_id, false) ->from('tbl_states'); //for search value datatable if(isset($_post['search']['value'])) { $this->db->like('state_name', $_post['search']['value']); } //for order datatable if(isset($_post['order'])) { $this->db->order_by($this->order_column[$_post['order']['0']['column']], $_post['order']['0']['dir']); } else { $this->db->order_by('id', 'desc'); } //$result = $query->result_array(); //return $result; } //get datatable public function get_states_table($country_id) { $this->get_states($country_id); if($_post["length"] != -1) { $this->db->limit($_post["length"], $_post["start"]); $query = $this->db->where('country_id', $country_id, false) ->get(); return $query->result_array(); } } function get_states_count_filtered($country_id) { $this->get_states($country_id); $query = $this->db->where('country_id', $country_id, false) ->get(); return $query->num_rows(); } public function get_states_count($country_id) { $this->db->where('country_id', $country_id, false) ->from('tbl_states'); return $this->db->count_all_results(); }
thank in advance.
in controller
from
$no = $_post['start'];
to
if(isset($_post['start']) && isset($_post['draw'])) { $no = $_post['start']; }else{ // need start , draw die(); // error }
and in model
from
if($_post["length"] != -1)
to
if(isset($_post["length"]) && $_post["length"] != -1)
Comments
Post a Comment