Skip to navigation
Example of datatable server side php processing
14.03.16
client: jQuery('.data_qcl').dataTable({ "aLengthMenu": [[100, 300, 500,1000, -1], [100, 300, 500,1000, "All"]], "processing": true, "serverSide": true, "ajax": "qcl/ajax_get_data" }); server: public function ajax_get_data() { $orders = ['0'=>'date','1'=>'supplier','2'=>'order_no','3'=>'line_no','4'=>'style','5'=>'qty','6'=>'b_qty','7'=>'worker_id','8'=>'worker_id','9'=>'dater']; $apps = $this->load->database('apps', TRUE); $draw = $this->input->get('draw'); $length = $this->input->get('length');; $start = $this->input->get('start'); $search = $this->input->get('search'); $order = $this->input->get('order'); $order_column = $order[0]['column']; $order_dir = $order[0]['dir']; if($order_column && $order_dir): $order = 'ORDER by dater'; if(isset($orders[$order_column])): $order = "ORDER BY {$orders[$order_column]} {$order_dir}"; endif; else: $order = 'ORDER by dater'; endif; $sk = $search['value']; $where = ''; if($sk): $a = explode('-',$sk); if(isset($a[0])): $day = $a[0]; $month = isset($a[1]) ? $a[1] : date('n'); $year = isset($a[2]) ? $a[2] : date('Y'); if(is_numeric($day) && is_numeric($month) && is_numeric($year)): $month = (int)$month; $year = (int)$year; $startdate = mktime(0, 0, 0, $month, (int)$day, $year) -2000; $enddate = $startdate + 180000; if($startdate): $where .= "WHERE dater > {$startdate} AND dater < {$enddate}"; endif; endif; endif; endif; $r = $apps->query("select * from qclists {$where} {$order}")->result(); $rdata = []; $c = 1; foreach($r as $k=>$i): $rdata[] =[ $c, $i->supplier, $i->order_no, $i->line_no, $i->style, $i->qty, $i->b_qty, $i->worker_id, $i->comment, date('d-m-Y',$i->dater), ]; $c++; endforeach; //var_dump($search['value']); $output = array_slice($rdata, $start, $length); $data = []; $data['draw'] = $draw; $data['recordTotal']= $length; $data['recordsFiltered'] = count($rdata); $data['data'] = []; $data['data'] = $output; $data = json_encode($data); $this->output->set_content_type('json')->set_output($data); }
https://datatables.net/manual/server-side
Reply
Anonymous
Information Epoch 1747240397
Save trees.
Home
Notebook
Contact us