将DataTables与CodeIgniter一起使用时出现的问题


Issues using DataTables with CodeIgniter

我在使用DataTables和CodeIgniter时遇到问题。我使用的图书馆位于https://github.com/IgnitedDatatables/Ignited-Datatables.从数据库中提取数据可以正常工作,但当我访问显示我的DataTable的视图时,会弹出此警报:"DataTables警告:table id=big_table-为行0请求未知参数'0'",并导致一个空表。

查看

<script type="text/javascript">
    $(document).ready(function () {
        var oTable = $('#big_table').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": '<?php echo base_url(); ?>index.php/subscriber/datatable',
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "iDisplayStart ": 20,
            "oLanguage": {
                "sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
            },
            "fnInitComplete": function () {
                //oTable.fnAdjustColumnSizing();
            },
            'fnServerData': function (sSource, aoData, fnCallback) {
                $.ajax
                ({
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': fnCallback
                });
            }
        });
    });
</script>
<?php echo $this->table->generate(); ?>

控制器

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Subscriber extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('Datatables');
        $this->load->library('table');
    }
    function index()
    {
        //set table id in table open tag
        $tmpl = array('table_open' => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="mytable">');
        $this->table->set_template($tmpl);
        $this->table->set_heading('First Name', 'Last Name', 'Email');
        $this->load->view("includes/header");
        $this->load->view('subscriber_view');
        $this->load->view("includes/footer");
    }
    //function to handle callbacks
    function datatable()
    {
        $this->datatables->select('id,first,last,email')
            ->unset_column('id')
            ->from('subscriber');
        echo $this->datatables->generate();
    }
}
?>

有什么解决方案吗?

将列定义添加到您的dataTable中,如:

        "columns": [
            { "data": "id" },
            { "data": "first" },
            { "data": "last" },
            { "data": "email" }
        ],