Welcome Guest, Not a member yet? Register   Sign In
Datatables for Codeigniter 3
#4

(This post was last modified: 12-01-2022, 09:12 AM by brianjamestorr.)

(11-30-2022, 12:30 PM)superior Wrote: There is a library available maybe this makes it easier for you?

https://github.com/cahyadsn/ci-datatables

Thanks man this solution is perfect and really easy to use  Angel

I use it this way in model/controller because of logic that i don't want to do in model. 

I hope this will help someone.

My model:

PHP Code:
$this->datatables->select('Id, Title, Plate');
$this->datatables->from('vehicles');
$results $this->datatables->generate('raw');

return 
$results

My controller:

PHP Code:
$data = [];

 
$result $this->Vozila_model->dohvati_vozila(); 

 foreach (
json_decode($result)->aaData as $val) {
   $buttons '';

   $data[] = array(
     $val[0],
     $val[1],
     $val[2],
     $buttons
   
);
 }

 
$output = array(
   'draw' => json_decode($result)->sEcho,
   'recordsTotal' => json_decode($result)->iTotalRecords,
 
   'recordsFiltered' => json_decode($result)->iTotalDisplayRecords,
   'data' => $data
 
);

 echo 
json_encode($output); 

My view, ajax:
Code:
var table = $('#data-table').DataTable({
    processing: true,
    serverSide: true,
    ajax: {
        url: '<?php echo base_url('vozila/gg'); ?>',
        type: 'post'
    }
});

(12-01-2022, 12:19 AM)InsiteFX Wrote: This may also help you out.

DataTables AJAX Pagination with Search and Sort in CodeIgniter 3

I tried this code and this one is too much to write or to place in function for reuse, also those 3 lines throwing error because default when you load table you doesn't have indexes set of  
PHP Code:
$postData['order'
until you click on header of the table.
If someone wants to use this you need to check for
PHP Code:
isset($_POST['order']) 
first and if is not set make default order by id or some other column.


PHP Code:
$rowperpage $postData['length']; // Rows display per page
$columnIndex $postData['order'][0]['column']; // Column index
$columnName $postData['columns'][$columnIndex]['data']; // Column name 
Reply


Messages In This Thread
Datatables for Codeigniter 3 - by brianjamestorr - 11-30-2022, 10:44 AM
RE: Datatables for Codeigniter 3 - by superior - 11-30-2022, 12:30 PM
RE: Datatables for Codeigniter 3 - by brianjamestorr - 12-01-2022, 09:06 AM
RE: Datatables for Codeigniter 3 - by InsiteFX - 12-01-2022, 12:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB