将DataTable与Codeigniter一起使用时,它显示的是处理而不是显示数据

时间:2014-08-10 13:54:21

标签: php jquery codeigniter datatables smarty

我试图将DataTables与CodeIgniter一起使用。

这是我迄今为止所做的。

1)将IgnitedDatatables库添加到我的库并将其调用到我的datatables控制器,

$this->load->library('Datatables.php');

2)查看

<table id="ManageForms" class="table table-bordered table-condensed table-hover table-striped">
    <thead>
        <tr>
            <th>Form Name</th>
            <th>Browser</th>
            <th>Platform(s)</th>
            <th>Engine version</th>
            <th>CSS grade</th>
        </tr>
    </thead>
</table>

<script>
    $(document).ready(function() {
        $('#ManageForms').dataTable({
            "processing":true,
            "serverSide":true,
            "bProcessing":true,
            "sServerMethod": "POST",
            "sAjaxSource": "{{base_url()}}admin/configurations/listForms_DT/",
            "iDisplayLength": 10,
            "aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
            "aaSorting": [[0, 'asc']],
            "aoColumns": [
                { "bVisible": true, "bSearchable": true, "bSortable": true },
                { "bVisible": true, "bSearchable": true, "bSortable": true },
                { "bVisible": true, "bSearchable": true, "bSortable": true }
            ],
            "columns": [
                { "data": "FormName" }
            ],
            'fnServerData'   : function(sSource, aoData, fnCallback){
                $.ajax ({
                    'dataType': 'json',
                    'type'    : 'POST',
                    'url'     : sSource,
                    'data'    : aoData,
                    'success' : fnCallback
                }); //end of ajax
            }

        });
    });
</script>

3)Json中的数据从路径返回此表格:

 {"data_DT":[{"FormID":"1","FormName":"Dashboard","FormPath":"#","FormCIPath":"admin\/dashboard\/System","IsMenuLink":"1","MenuID":"1","FormRoleID":"1","RoleID":"1","IsDeleteable":"1","IsEditable":"1","IsCreatable":"1"},{"FormID":"2","FormName":"Dashboard","FormPath":"#","FormCIPath":"admin\/dashboard\/Users","IsMenuLink":"1","MenuID":"2","FormRoleID":"2","RoleID":"1","IsDeleteable":"1","IsEditable":"1","IsCreatable":"1"},{"FormID":"3","FormName":"Residensials","FormPath":"#","FormCIPath":"#","IsMenuLink":"1","MenuID":"3","FormRoleID":"3","RoleID":"1","IsDeleteable":"1","IsEditable":"1","IsCreatable":"1"},{"FormID":"6","FormName":"Configuration","FormPath":"#","FormCIPath":"#","IsMenuLink":"1","MenuID":"6","FormRoleID":"4","RoleID":"1","IsDeleteable":"1","IsEditable":"1","IsCreatable":"1"},{"FormID":"7","FormName":"ManageForms","FormPath":"#","FormCIPath":"admin\/configurations\/ManageForms","IsMenuLink":"1","MenuID":"7","FormRoleID":"5","RoleID":"1","IsDeleteable":"1","IsEditable":"1","IsCreatable":"1"}]}

现在的问题是我的DataTables而不是显示天数,显示处理??

我不知道哪里出错了,请问如果有人能解决问题或重定向我做错了什么?

1 个答案:

答案 0 :(得分:1)

此消息表示,DataTable无法正确读取您的数据。

使用默认设置,您的ajax请求必须将数据返回到aaData对象。