我已经引用此链接来使我的codeigniter数据表基于ajax的datatable。Codeigniter Ajax Datatable显示错误
http://mbahcoding.com/tutorial/php/codeigniter/codeigniter-simple-server-side-datatable-example.html
但它示出了错误,并且不表示在数据表中的数据。
消息:未定义指数:长度
消息:未定义指数:启动
消息:未定义指数:画
请别人帮我删除这些错误。
我的Jquery
$(document).ready(function(){
//Ajax Datatable
//datatables
var dataTable = $('#dataTables-suburb').DataTable({
processing: true, //Feature control the processing indicator.
serverSide: true, //Feature control DataTables' server-side processing mode.
order: [], //Initial no order.
// Load data for the table's content from an 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
},
],
});
});
我的控制器功能
public function state_table_ajax()
{
$data['details'] = $this->LoginModel->admin_details($this->session->userdata('admin-username'));
foreach($data['details'] as $detail):
$country_id = $detail['country_id'];
endforeach;
$states = $this->StatesModel->get_states_table($country_id);
$no = $_POST['start'];
foreach($states as $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 to json format
echo json_encode($output);
}
我的标准守则
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();
}
预先感谢您。
显示您的Html和Jquery代码 –
现在显示这一个becoz我已经在另一个函数中调用ajax,并在另一个函数中查看。 DataTables警告:表id = dataTables -suburb - Ajax错误。有关此错误的更多信息,请参阅http://datatables.net/tn/7 –
他们提供了显示错误是什么以及如何解决它的链接。 –