datatables使用ajax获取数据

前端:

//初始化datatable
var
table3 = $('.jiaoshi_lst').DataTable({ "processing": true, "serverSide": true, "paging": true, "ordering": false, "searching": false, "select": true, "ajax": { url: "get_lst", type: "get", dataType: 'json' }, "columns": [ { 'data': null, "render": function (data, type, full, meta) { var div = `<div class="dt-checkbox"> <input type="checkbox" name="select_all" value="`+ data.id + `" id="example-select-all"> <span class="dt-checkbox-label"></span> </div>`; return div; } }, { 'data': 'id' }, { 'data': 'classroom' }, { 'data': 'area' }, { 'data': 'loudong' }, { 'data': 'id', "render": function (data, type, full, meta) { var div = `<a href="javascript:;" class="btn-sm btn-primary btn-edit mm-margin-right"><i class='fa fa-pencil'></i></a> <a href="javascript:;" class="btn-sm btn-danger btn-del" data-uid="${data}"><i class='fa fa-times'></i></a>`; return div; } }, ] });

 

 

后台:

 function room_get_lst()
  {
    $offset = $this->input->get('start');
    $pager = $this->input->get('length');
    $result = [
      'draw' => $this->input->get('draw'),
      'recordsTotal' => $this->db->get('shebei')->num_rows(),
      'recordsFiltered' => $this->db->get('shebei')->num_rows(),
      'data' => $this->db->select('id,area,loudong,classroom')->limit($pager, $offset)->get('jiaoshi')->result_array()
    ];

    $rs = json_encode($result);
    die($rs);
    echo $rs;
  }

 

posted @ 2024-10-11 17:52  哆啦阿梦  阅读(10)  评论(0编辑  收藏  举报