如何在codeigniter中执行排序,搜索,分页

时间:2015-10-30 06:39:15

标签: codeigniter sorting search pagination

我是一个更新鲜的codeigniter。我想搜索,排序和应用分页到我的表。 我尽力了。当搜索代码工作时,排序可能无法正常工作。我无法在一个表格中执行这三个操作。请帮我。

1 个答案:

答案 0 :(得分:0)

使用Bootstrap datatables。它也有内置的搜索,排序和分页。

我的代码示例

在视图中

<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>

在控制器中

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

在标题中

<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" />

<强>输出

enter image description here

相关问题