Server side DataTables with Ignited-Datatables Lib

2020-04-21 00:07发布

How to Server side DataTables with Ignited-Datatables Library?

My application use CodeIgniter.

Library that I use is Ignited-datatables Library.

My controller is like this :

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

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>

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 ?

Thank you.

1条回答
做自己的国王
2楼-- · 2020-04-21 00:50

There is error in your Code.

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.

查看更多
登录 后发表回答