【发布时间】:2019-01-26 02:16:50
【问题描述】:
我试图实现数据表服务器端,因为我有一个非常大的表,它不能像往常一样返回数据表,但是我有一个问题,我不知道发生了什么,因为它不工作:
查看:
<table id="deposits" class="table table-bordered table-striped">
<thead>
<tr>
<th>Id</th>
<th>Sucursal</th>
</tr>
</thead>
</table>
JS:
$("#deposits").DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
'responsive': true,
"processing": true,
"serverSide": true,
"ajax":{
url :"<?php echo base_url(); ?>deposit/data", // json datasource
type: "post", // method , by default get
error: function(data) { // error handling
console.log(data);
}
},
"columns": [
{ "data": "id" },
{ "data": "branch_name" },
],
"columnDefs": [
{
"targets": [ 1 ],
"visible": false,
"searchable": false
},
{
"targets": [ 2 ],
"visible": false
}
],
"language": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "No se encontraron resultados",
"sEmptyTable": "Ningún dato disponible en esta tabla",
"sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
"sInfoPostFix": "",
"sSearch": "Buscar: ",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "Cargando...",
"oPaginate": {
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria": {
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
},
},
"order": [[ 8, "desc" ]],
});
控制器:
public function data()
{
$data = array(
'id_user' => $this->session->userdata('id_user'),
'activity_type' => 4,
);
$this->activity_model->store($data);
$id_status = $this->uri->segment(2);
if($this->session->userdata('id_user_type') == 4)
{
$data = array(
'id_supervisor' => $this->session->userdata('id_user'),
'id_status' => $id_status,
'start' => $this->input->post('start'),
'length' => $this->input->post('length'),
);
$result = $this->deposit_model->getDataTableDeposits($data);
}
else
{
if($id_status != "")
{
$data = array(
'id_status' => $id_status,
'start' => $this->input->post('start'),
'length' => $this->input->post('length'),
);
}
else
{
$data = array(
'start' => $this->input->post('start'),
'length' => $this->input->post('length'),
);
}
$result = $this->deposit_model->getDataTableDeposits($data);
}
$data = $result['data'];
$recordsTotal = $result['numDataTotal'];
for ($i = 0; $i < $recordsTotal; $i++) {
$array = array();
$array['id_deposit'] = $data[$i]['id_deposit'];
$array['branch_office'] = $data[$i]['branch_office'];
$new_data[] = $array;
}
$recordsFiltered = $recordsTotal;
$json_data = array(
"draw" => intval($this->input->post('draw')),
"recordsTotal" => intval($recordsTotal),
"recordsFiltered" => intval($recordsFiltered),
"data" => $new_data
);
echo json_encode($json_data);
}
型号:
function getDataTableDeposits($data = NULL)
{
$this->db->select('deposits.*, branch_offices.*, statuses.*, DATE_FORMAT(deposits.date,"%d/%m/%Y") AS date, DATE_FORMAT(deposits.collection_date,"%d/%m/%Y") AS collection_date');
$this->db->from('deposits, branch_offices, statuses');
$this->db->where("deposits.id_branch_office = branch_offices.id_branch_office");
$this->db->where("deposits.id_status = statuses.id_status");
$this->db->limit($data['start'], $data['length']);
if(isset($data['id_status']))
{
$this->db->where("deposits.id_status != 7");
}
else
{
$this->db->where("deposits.id_status = 7");
}
$this->db->order_by("deposits.date", "desc");
if(isset($data['id_supervisor']))
{
$this->db->where("deposits.id_supervisor = '".$data['id_supervisor']."'");
}
$query = $this->db->get();
$return = array(
'numDataTotal' => $query->num_rows(),
'data' => $query->result_array()
);
return $return;
}
但问题是它没有返回任何东西,它只是保持空白,它只显示标题 Id 和 Sucursal 但没有数据。
会是什么?因为我学过一些课程,我真的不明白我还需要什么......
谢谢。
【问题讨论】:
标签: php codeigniter datatable