Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function load_grid() {
- table = $('#table_grid').DataTable({
- "scrollX": true,
- "processing": true, //Feature control the processing indicator.
- "serverSide": true, //Feature control DataTables' server-side processing mode.
- // Load data for the table's content from an Ajax source
- "ajax": {
- "url": "<?php echo base_url().'Position/ajax_list'?>",
- "type": "POST"
- },
- //Set column definition initialisation properties.
- "columnDefs": [
- {
- "targets": [ -1 ], //last column
- "orderable": false, //set not orderable
- // "className":'mdl-data-table__cell--non-numeric'
- },
- ],
- });
- }
- -------------------------------------------------------------------------------------
- ----------------------------CONTROLLER-----------------------------------------------
- public function ajax_list()
- {
- $btn = '';
- $list = $this->m_position->get_datatables();
- $data = array();
- $no = $_POST['start'];
- foreach ($list as $position) {
- $no++;
- $row = array();
- $row[] = $no;
- $row[] = $position->div_code;
- $row[] = $position->position_code;
- $row[] = $position->position_desc;
- $row[] = $position->is_active;
- $row[] = '<a class="btn btn-sm btn-info1" href="javascript:void()" title="Edit" onclick="edit_position('."'".$position->pid."'".')"><i class="glyphicon glyphicon-pencil"></i> Edit</a>
- <a class="btn btn-sm btn-danger1" href="javascript:void()" title="Hapus" onclick="delete_position('."'".$position->pid."'".')"><i class="glyphicon glyphicon-trash"></i> Delete</a>';
- $data[] = $row;
- }
- $output = array(
- "draw" => $_POST['draw'],
- "recordsTotal" => $this->m_position->count_all(),
- "recordsFiltered" => $this->m_position->count_filtered(),
- "data" => $data,
- );
- //output to json format
- echo json_encode($output);
- }
- ---------------------------------------------------------------------------------
- -------------------------MODEL---------------------------------------------------
- private function _get_datatables_query()
- {
- $this->db2->from($this->table);
- $i = 0;
- foreach ($this->column as $item)
- {
- if($_POST['search']['value'])
- ($i===0) ? $this->db2->like($item, $_POST['search']['value']) : $this->db2->or_like($item, $_POST['search']['value']);
- $column[$i] = $item;
- $i++;
- }
- if(isset($_POST['order']))
- {
- $this->db2->order_by($column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
- }
- else if(isset($this->order))
- {
- $order = $this->order;
- $this->db2->order_by(key($order), $order[key($order)]);
- }
- }
- function get_datatables()
- {
- $this->_get_datatables_query();
- if($_POST['length'] != -1)
- $this->db2->limit($_POST['length'], $_POST['start']);
- $query = $this->db2->get();
- return $query->result();
- }
- function count_filtered()
- {
- $this->_get_datatables_query();
- $query = $this->db2->get();
- return $query->num_rows();
- }
- public function count_all()
- {
- $this->db2->from($this->table);
- return $this->db2->count_all_results();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement