попробуйте это: я надеюсь, что это поможет вам.// js
var dtable = $('#view-stock').DataTable({
processing: true,
serverSide: false,
searching: true,
dom: 'lBfrtip',
lengthMenu: [[5, 10, 25, 50, 100, -1], [5, 10, 25, 50, 100, "All"]],
pageLength: 10,
buttons: [
'csv', 'print'
],
ajax: {
"url": base_url + "/stock/datatables",
'method': 'POST',
'data': function (d) {
d._token = $("input[name=_token]").val();
}
}
//controller
function index() {
$data = array();
$data['view'] = 'view_page_name';
$this->load->view('header', $data);
}
function datatables() {
$data = array();
$stock =$this->Stock_model->get_stock($this->input->post());
parent::json_output(["draw" => intval($this->input->post('draw')), "recordsTotal" => $stock[1], "recordsFiltered" =>$stock[1], "data" => $stock[0]]);
return;
}
// модель
function get_stock($requestArray) {
if (isset($requestArray['keyword']) && $requestArray['keyword'] != '') {
$this->db->where .= " AND (field_name_by_which_you_want_search LIKE '%" . $requestArray['keyword'] . "%')";
$this->db->where .= " AND (field_name_by_which_you_want_search LIKE '%" . $requestArray['keyword'] . "%')";
}
$this->db->where($where);
if ($this->input->post('length') != '-1') {
$this->db->limit($this->input->post('length'), $this->input->post('start'));
}
$this->db->order_by('id','desc');
$query = $result->get('stockdetail')->result_array();
$count = $result->get('stockdetail')->num_rows();
return [$query, $count];
}