服务器端数据表与点燃的数据表库



如何使用已点燃的数据库库创建服务器端数据表?

我的应用程序使用CodeIgniter

我使用的库是ignition -datatable 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>

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

谢谢。

您的代码中有错误。

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

您缺少echo前的分号。我正在使用您的代码,一切工作正常后放入分号。

最新更新