开发者

jquery datatable and cakePHP

开发者 https://www.devze.com 2023-02-12 04:07 出处:网络
i am trying to implement jquery datatable, in my cakePHP based website, but it just wont load. this website is already half de开发者_如何转开发veloped, and from the way i see it, the js\' is loaded th

i am trying to implement jquery datatable, in my cakePHP based website, but it just wont load. this website is already half de开发者_如何转开发veloped, 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


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


You should use the find function in your controller and pass the array to the view and in the view write it.. don't just leave the table empty

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号