how to perform sorting,search,pagination in codeigniter

前端 未结 1 902
-上瘾入骨i
-上瘾入骨i 2021-01-23 11:02

I\'m a fresher in codeigniter. I want to search,sort and apply pagination to my table. I tried my best.when search code is working sorting may not work. i can\'t perform these t

相关标签:
1条回答
  • 2021-01-23 11:26

    use Bootstrap datatables. It has in built search, Sort and pagination too.


    Sample of My code

    In View

    <div style="clear: both; margin-top: 35px"></div>
    <div class="container">
        <div class="col-sm-12" style="padding: 0px">
            <div class="row">
                <div class="col-sm-10 col-sm-offset-1 " style="padding-right:0px;">
                    <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
    
                        <thead>
                        <tr>
                            <th width="20%"></th>
                            <th width="15%"></th>
                            <th width="20%"></th>
                            <th width="15%"></th>
                            <th width="10%"></th>
                        </tr>
                        </thead>
                        <tbody>
                        <?
                            foreach ( $ as $ )
                            {
                                ?>
                                <tr>
                                    <td><?php echo $['']?></td>
                                    <td><?php echo $['']?></td>
                                    <td><?php echo $['']?></td>
                                    <td><?php echo $['']?></td>
                                </tr>
                            <?
                            }
    
                        ?>
    
                        </tbody>
                    </table>
                </div>
    
            </div>
        </div>
    </div>
    

    In Controller

    $data[''] = $this->model_name->function_name();
    

    In Header

    <link href="<?php echo base_url(); ?>css/bootstrap.css" rel="stylesheet" /> 
    <link href="<?php echo base_url(); ?>css/bootstrap-glyphicons.css" rel="stylesheet" />
    <link href="https://cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet" />
    

    Output

    0 讨论(0)
提交回复
热议问题