Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery datatable and cakePHP

i am trying to implement jquery datatable, in my cakePHP based website, but it just wont load. this website is already half developed, and from the way i see it, the js' is loaded through a file called _head.inc.ctp located inside the views/layouts folder, i have added the datatables library inside the libs folder which is webroot/js/libs and load it inside the _head.inc.ctp file.

suppose i have this: my controller:

var $helpers = array(
    'Form',
    'Html',
    'Javascript'
);
//my method
function dataTable_example($id=null){
    $details = $this->Detail->find("all");
    $this->set('details', $details );
}

my view:

<div>
    <?php echo $javascript->link('libs/jquery.dataTables.js'); ?>
<script>
    $(document).ready(function(){
        $('#js-datatable').dataTable();
    });
</script>
    <h2><?php echo __l('Tickets');?></h2>
    <div>
        <table id="js-datatable">
            <tr>
                <th>some heading 1</th>
                <th>some heading 1</th>
                <th>some heading 1</th>
            </tr>
            <?php
            if (!empty($details)){
                foreach ($details as $detail):
            ?>
            <tr>
                <td><?php echo $detail['Detail']['id'];?></td>
                <td><?php echo $detail['Detail']['created'];?></td>
                <td><?php echo $detail['Detail']['ticket_detail'];?></td>
            </tr>
            <?php
                endforeach;
            }else{
            ?>
            <tr>
                <td>No Data Found</td>
            </tr>
            <?php }?>
        </table>
    </div>
</div>

i even hard coded it using the usual call, and checked it using firebug to see if the script is loaded or not, and according to firebug, it is loaded, so i cant see whats making the script fail my table.

did i missed some steps ? please help

thanks

like image 847
littlechad Avatar asked Oct 12 '22 16:10

littlechad


1 Answers

You don't have thead and tbody elements as required by the datatables script

like image 193
supermethod Avatar answered Oct 19 '22 23:10

supermethod