0

我正在按照本教程使用 DataTables 和 CodeIgniter 。

在加载视图时,控制台中出现错误:

Type Error: 1 is undefined in jquery.dataTables.min.js 49:323

我的控制器代码是:

    public function index()
{
    if($this->session->userdata('logged_in'))
    {
        $this->load->library('table');
        $tmpl = array('table_open' => '<table id="doc_table"">');
        $this->table->set_template($tmpl);
        $this->table->set_heading('TMT_PK_Key', 'Name');
        $this->load->view('doctor');
    }
    else
    {
        redirect('home');
    }
}

function getDocData()
{
    $this->load->library('Datatables');
    $this->datatables
        ->select('TMT_PK_Key, Name')
        ->from('Doctor_Basic');
        //->join('Doctor_Email', 'Doctor_Basic.TMT_PK_key = Doctor_Email.TMT_PK_key')
        //->select('Email')
        //->join('Doctor_Mobile', 'Doctor_Basic.TMT_PK_key = Doctor_Mobile.TMT_PK_key')
        //->select('Mobile');

    echo $this->datatables->generate();
}
}

我的视图代码(一些代码被省略,如 js 调用):

<html>
<body>
    <?php echo $this->table->generate(); ?>
</body>
</html>

JS

jQuery(document).ready(function () {
    var oTable = jQuery('#doc_table').dataTable({
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": '/ci/doctor/getDocData',
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "iDisplayStart ": 100,
        "oLanguage": {
            "sProcessing": "<img src='/ci/images/loading.gif'>"
        },
        'fnServerData': function (sSource, aoData, fnCallback) {
        jQuery.ajax
        ({
            'dataType': 'json',
            'type': 'POSt',
            'url': sSource,
            'data': aoData,
            'success': fnCallback
        });
    },
});

});

返回的数据(检查元素=>网络=>响应):

draw:0
recordsTotal:1331
recordsFiltered:1331
data:Array
   0:Object
   TMT_PK_Key:"TMTPK"
   Name:"ABC"

我尝试在论坛中查找,但找不到解决方案。任何帮助将不胜感激。

4

1 回答 1

0

我通过从这里将 DataTables 更新到 1.10.5 解决了这个问题

于 2015-03-15T05:18:58.810 回答