Datagrid Easyui不起作用

Help. Datagrid EasyUI Not Work Error :

jquery.easyui.min.js:11286 Uncaught TypeError: Cannot read property 'length' of undefined
    at Object.renderTable (jquery.easyui.min.js:11286)
    at Object.render (jquery.easyui.min.js:11263)
    at _6e1 (jquery.easyui.min.js:10149)
    at HTMLTableElement.<anonymous> (jquery.easyui.min.js:11055)
    at Function.each (jquery.min.js:2)
    at m.fn.init.each (jquery.min.js:2)
    at Object.loadData (jquery.easyui.min.js:11054)
    at m.fn.init.$.fn.datagrid (jquery.easyui.min.js:10816)
    at jquery.easyui.min.js:10770
    at Object.success (jquery.easyui.min.js:11526)

Code in : https://pastebin.com/Y2L8UyeV

Controller Pencatatan.php

class Pencatatan extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->model('M_Pencatatan');
    }
    function index(){
        $data['title'] = 'Pencatatan Transaksi';
        $data['content'] = 'V_Pencatatan';

        $this->load->view('Template/full',$data);
    }

    function data()
    {
        $data['datatables'] = $this->M_Pencatatan->show_keuangan_all();
        echo json_encode($data);
    }
}   

Model M_Pencatatan.php

function show_keuangan_all(){
    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
    $sort = isset($_POST['sort']) ? strval($_POST['sort']) : 'id_keuangan';
    $order = isset($_POST['order']) ? strval($_POST['order']) : 'asc';
    $offset = ($page-1) * $rows;

    $result = array();
    $result['total'] = $this->db->get('keuangan')->num_rows();
    $row = array();

    $this->db->limit($rows,$offset);
    $this->db->order_by($sort,$order);
    $criteria = $this->db->get('keuangan');

    foreach($criteria->result_array() as $data)
    {  
        $row[] = array(
                'id'=>$data['id_user'],
                'keterangan'=>$data['keterangan'],
                'value'=>$data['value'],
                'tanggal'=>$data['tanggal_transaksi']
            );
        }

        $result=array_merge($result,array('rows'=>$row));
        return $result;
    }  

}

Full View

<html>
<head>
    <meta charset="UTF-8">
    <title>Pencatatan</title>
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>asset/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>asset/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>asset/demo/demo.css">
    <script type="text/javascript" src="<?php echo base_url(); ?>asset/jquery.min.js"></script>
    <script type="text/javascript" src="<?php echo base_url(); ?>asset/jquery.easyui.min.js"></script>
    <script type="text/javascript">
    window.setTimeout("waktu()",1000);
    function waktu() {
        var tanggal = new Date();
        setTimeout("waktu()",1000);
        document.getElementById("jam").innerHTML = tanggal.getHours();
        document.getElementById("menit").innerHTML = tanggal.getMinutes();
        document.getElementById("detik").innerHTML = tanggal.getSeconds();
    }
    </script>
</head>
<body class="easyui-layout">
    <div data-options="region:'north',border:false" style="height:60px;background:#B3DFDA;padding-left:5px;padding-right:5px">
        <table width="100%">
            <tr>
                <td style="width:50%;"><font size="5px;" color="#00004d"><b>Pencatatan Keuangan</b></font></td>
                <td style="width:50%;" align="right">

                </td>  
            </tr>  
            <tr>
                <td><font size="2px;" color="#7c7c50">Selamat Datang, </font></td>
                <td align="right"><font size="3px;" color="#00004d"><b><?php echo date('d F Y'); ?> &nbsp;&nbsp;&nbsp;&nbsp;<Font id="jam" style=""></Font>:
                    <Font id="menit"></Font>:
                    <Font id="detik"></Font></b></font></td>
            </tr>
        </table>
    </div>
    <div data-options="region:'west',split:true,title:'Main Menu'" style="width:150px;" class="easyui-accordion">
        <div title="Transaction" data-options="iconCls:'icon-search'">
            <ul class="easyui-tree">
                <li>
                    <span>Transaction</span>
                    <ul>
                        <li>
                            <a style="color:black;text-decoration:none;" href="<?php base_url();?>Pencatatan" data-options="plain:true" onclick="addPencatatan()">Pencatatan</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div data-options="region:'east',split:true,collapsed:true,title:'East'" style="width:100px;padding:10px;">east region</div>
    <div data-options="region:'south',border:false,split:false" style="height:25px;background:#A9FACD;padding:0px;"><font size="2px;" color="#00004d"><b><center>&#169; Tuyullie</center></b></font></div>
    <!-- Sub Main -->
    <div data-options="region:'center',title:'Web Dashboard'">
        <div id="tt" class="easyui-tabs" data-options="tools:'#tab-tools'" style="width:100%;height:100%">
            <?php if(isset($content)) {$this->load->view($content);} ?>
        </div>
    </div>
    <script type="text/javascript">
    function addPencatatan(){
        $('#tt').tabs('add',{
            title: 'Pencatatan',
            closable: true
        });
    }
    </script>
    <!-- End Sub Main -->
</body>
</html>


V_Pencatatan.php View
<table id="dg"></table>
<!-- Toolbar -->
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="create()"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="update()"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="remove()"></a>
</div>
<script>
$(document).ready(function(){
    $('#dg').datagrid({
        border: false,
            title: "Pencatatan",
            fit: true,
            class: "easyui-datagrid",
            pagination: true,
            pageSize: 50,
            striped: true,
            sortName: "id_user",
            sortOrder: "desc",
            pageList: [50, 100, 150, 200, 250],
            rownumbers: true,
            fitColumns: true,
            singleSelect: true,
        url:'Pencatatan/data',
        columns:[[
            {field:'id',tittle:'ID',width:100},
            {field:'keterangan',tittle:'Keterangan',width:100},
            {field:'value',tittle:'Value',width:100},
            {field:'tanggal',tittle:'Tanggal',width:100}
        ]]
    })
})
</script>
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐