具有Ignited-Datatables Library的服务器端DataTables

时间:2015-10-19 04:40:53

标签: jquery datatables

如何使用Ignited-Datatables Library服务器端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>

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

谢谢。

1 个答案:

答案 0 :(得分:1)

您的代码中存在错误。

module.exports

你在回声之前错过了Semi Colon。 我正在使用你的代码,放入半冒号后一切正常。