Welcome Guest, Not a member yet? Register   Sign In
Ignited Datatables - display the records on the table
#1

Hi I'd like some help please.

I'm using Ignited Datatables to display posts in tabular way in my view. I've been struggling hole weekend in order to do this working correct, but I can't understand what or if I'm doing something wrong.

This is the function that fetches the tabular data in my Post model
PHP Code:
/**
    * Get page data on datatables
    */
    
public function get_datatable() {
        
        
$this->load->library('datatables');

        
$this->datatables->select('id, title, slug, date_published, status');
        
$this->datatables->from('posts');
        return 
$this->datatables->generate();
    } 

Then in my posts controller I call the get_datatable()

PHP Code:
/**
    * List all posts
    */
    
public function index() {

        
$this->data['datatables'] = true;
        
$this->data['data_url'] = 'admin/posts/index';
        
$this->data['posts'] = $this->post_model->get_datatable();
        
        
// load view
        
$this->load->view('admin/posts/index'$this->data);
    } 

And this is my view

Code:
<table class="table dataTable table-bordered" cellspacing="0" width="100%">
   <thead> <!-- TODO - Display the headings: Title, Date Published, Url Slug -->
      <tr>
         <th>Name</th>
         <th>Position</th>
         <th>Office</th>
         <th>Age</th>
         <th>Start date</th>
         <th>Salary</th>
      </tr>
   </thead>

   <tfoot>
      <tr>
         <th>Name</th>
         <th>Position</th>
         <th>Office</th>
         <th>Age</th>
         <th>Start date</th>
         <th>Salary</th>
      </tr>
   </tfoot>

   <tbody></tbody> <!-- TODO - Display the posts -->
</table>

And this is my script

PHP Code:
<?php if(isset($datatables)): ?>
        <script  type="text/javascript" src="<?php echo base_url('js/dataTables/jquery.dataTables.min.js'); ?>">
        <script  type="text/javascript" src="<?php echo base_url('js/dataTables/dataTables.bootstrap.min.js'); ?>">
        
        <script type="text/javascript">
            $(document).ready(function() {
                $('.dataTable').DataTable({
                    'bProcessing' : true,
                    'bServerSide' : true,
                    'sAjaxSource' : '<?php echo base_url($data_url); ?>',
                    'sServerMethod' : 'POST',
                    'fnServerData' : function (sSource, aoData, fnCallback) {
                        $.ajax({
                            dataType : 'json',
                            type : 'post', 
                            url : sSource,
                            data : aoData,
                            success : fnCallback,
                        });
                    }
                });
            });
        </script>
    <?php endif; ?>

Any help would be appreciated.
Reply


Messages In This Thread
Ignited Datatables - display the records on the table - by Lykos22 - 09-21-2015, 01:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB