【问题标题】:Server side DataTables with Ignited-Datatables Library带有 Ignite-Datatables 库的服务器端 DataTables
【发布时间】:2015-10-19 04:40:53
【问题描述】:

如何使用 Ignited-Datatables 库来服务端 DataTables?

我的应用程序使用 CodeIgniter。

我使用的库是Ignited-datatables Library

我的控制器是这样的:

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

我的 HTML 是这样的:

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

我的 Javascript 是这样的:

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

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

谢谢。

【问题讨论】:

  • 您需要在服务器端代码中处理搜索、过滤和分页。参数已包含在数据表请求中。 https://datatables.net/development/server-side/php_mysql
  • @markpsmith,感谢您回答我的问题。它会修改 Ignited-Datatables 库吗?我仍然难以实施 Codeigniter。
  • check 这个。我想它可能会对你有所帮助。还有一件事我想提一下,即使用数据表“长度”和“开始”请求参数的限制。还有一个请求参数 'search[value]' 和 'search[regex]' 。我觉得链接就够了
  • 而且我完全自己处理了服务器端代码。我没有使用任何库。我对“点燃的数据表库”一无所知
  • @AbhisekMalakar,感谢您回答我的问题。但是,我仍然很难在我的应用程序中实现。太难了

标签: jquery datatables


【解决方案1】:

您的代码中有错误。

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

}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2019-05-25
    • 2015-03-10
    • 1970-01-01
    相关资源
    最近更新 更多