Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
jquery dataTable
  • Hi !! now i starts in learn fuelphp(beginner level)
    i want to know how to use jquery dataTables in fuelphp.Pls share and explain with example code.
    but it doesn't appear in my view page!
    here my code! 
    in view page

    <script> 
     jQuery(document).ready(function() {
     oTable = jQuery('#dtshops').dataTable({ 
     "processing": true,
     "serverSide": true, 
     "pagingType": "full_numbers", 
     "stateSave": true, 
     "jQueryUI": true, 
     "aaSorting": [[0,"asc"]], 
     "sAjaxSource": "shops/getlist",
     "columns":[
     { "bSortable": true, "sWidth": "auto" },
     { "bSortable": true, "sWidth": "auto" },
     { "bSortable": true, "sWidth": "auto" },
    { "bSortable": false, "sWidth": "auto" }
     });
     jQuery('.dataTables_filter').hide(); 
     } ); 
    </script>
     <table id="dtshops" name="dtshops" class="table table-striped"> 
    <h1>Shops List</h1>
     <thead> 
     <tr>
    <th>Name</th>
    <th>Address</th>
    <th>Rate</th>
    <th>Action</th>
    </tr>
     </thead> 
     <tfoot>
     <tr>
    <th>Name</th>
    <th>Address</th>
    <th>Rate</th>
    <th>Action</th>
    </tr>
     </tfoot>
     <tbody> 
     <td colspan="4">Loading data server</td>
    </tbody> 
    </table>

    in contoller 
        public function action_getlist()
            {   
                  $offset = Input::get('iDisplayStart');
    $max = Input::get('iDisplayLength');
                
                   $pref =   Model_Shops::query()
                                       ->order_by('id', 'ASC')
                                       ->rows_offset($offset)
                                       ->rows_limit($max)
                                       ->get();
                  
                   $iTotal = Model_Shops::count();
                   $data = array('sEcho'=>Input::get('sEcho'), 'iTotalRecords'=>$iTotal, 'iTotalDisplayRecords'=>$iTotal, 'aaData'=>array());
                     
                    foreach ($pref as $prefecture)
                    {
                            $tmpentry = array();
                            $tmpentry[] = htmlspecialchars($prefecture->name);
                            $tmpentry[] = htmlspecialchars ($prefecture->address);
                            $tmpentry[] =  htmlspecialchars ($prefecture->average_rate); $tmpentry[]=array(Html::anchor('shops/editShops/'.$prefecture>id,'Update',array('class'=>'btn btn-default')),Html::anchor('shops/deleteShops/'.$prefecture->id, 'Delete', array('onclick' => "return confirm('Are you sure?')",'class'=>'btn btn-default')));
                          $data['aaData'][] = $tmpentry;
                    }
    $this->template->content = View::forge('shops/index', $data);
            }
  • hey i can suggest you tu put that in a separate file in assets an check your console on the browser, maybe you are not loading jquery or is not detecting it that sometimes is main problem.
  • thanks you. i got it

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion