带有 Ignited-Datatables 库的服务器端数据表 [英] Server side DataTables with Ignited-Datatables Library

查看:19
本文介绍了带有 Ignited-Datatables 库的服务器端数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Ignited-Datatables 库来服务端数据表?

How to Server side DataTables with Ignited-Datatables Library?

我的应用程序使用 CodeIgniter.

My application use CodeIgniter.

我使用的库是 Ignited-datatables 库.

我的控制器是这样的:

public function get_book()
{
    $this->datatables->select('id, hotel, city, country, region')
                ->unset_column('id')
                ->from('hotel_book')
    echo $this->datatables->generate('json', '');
}

我的 HTML 是这样的:

My HTML is like this:

                    <table id="example">
                        <thead>
                          <tr>                         
                            <th>Hotel</th>
                            <th>City</th>
                            <th>Country</th>
                            <th>Region</th>                                                   
                          </tr>
                        </thead>
                    </table>

我的 Javascript 是这样的:

My Javascript is like this:

<script type="text/javascript">
            var table = $('#example').dataTable( {


                "order": [[ 1, "asc" ]],
                
                "aoColumnDefs": [
                    { 'bSortable': false, 'aTargets': [ 3 ]},
                    { 'bSearchable': true }
                ],
                "Processing": true,
                "ServerSide": true,
                "sAjaxSource": '<?php echo site_url(); ?>book/get_book',
                "bJQueryUI": true,
                "sPaginationType": "full_numbers",
                "iDisplayStart ":20,
                "oLanguage": {
                "sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
                },      
                
                "columns": [
                        { "data": "hotel" },
                        { "data": "city" },
                        { "data": "country" },
                        { "data": "region" }
                ],  

                'fnServerData': function(sSource, aoData, fnCallback)
                {
                    $.ajax
                    ({
                        'dataType': 'json',
                        'type'    : 'POST',
                        'url'     : sSource,
                        'data'    : aoData,
                        'success' : fnCallback
                    });
                }
            } );
</script>

如何在服务器端进行搜索、过滤和分页?

How to make searching, filter and paging into server side ?

谢谢.

推荐答案

您的代码中存在错误.

public function get_team()
{
    $this->load->library('Datatables');
    $this->datatables->select('*')
                ->unset_column('id')
                ->from('oric_team');
   echo $this->datatables->generate('json', '');

}

您在回声之前缺少分号.我正在使用您的代码,在输入分号后一切正常.

You are missing the Semi Colon before echo. I am using your code and everything is working fine after putting semi colon.

这篇关于带有 Ignited-Datatables 库的服务器端数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆