DataTable with Ajax is not working well after use serverSide: true

前端 未结 3 1320
傲寒
傲寒 2020-12-11 06:49

I have an user table using DataTables, that will contain more than 200 rows. It\'s look so fine when I\'m using DataTables for default the \"pageLength\": 10, a

3条回答
  •  星月不相逢
    2020-12-11 07:21

    As long as you chose the server mode, you have to manage everything via the requests. So, you have to dynamically create the values of the output array :

    $output = array(
        "draw" => $_POST['draw'],
        "recordsTotal" => $this->my_model->get_total_records(),
        "recordsFiltered" => $this->my_model->get_total_filtered(),
        "data" => $this->my_model->all_user_request($id)
    );
    

    and the model functions

    public function all_user_request($task_id) {
        $query = "SELECT * FROM user_request WHERE task_id = ?"; // add limit $_POST['length'], $_POST['start'] to your request
    
        return $this->db->query($query, $task_id)->result();
    }
    

提交回复
热议问题