1、加載本地數據
var obj = {"total":2,"rows":[{id:"1",name:"一"},{id:"2",name:"二"}]}; $('#dg').datagrid('loadData',obj);
注意:這里的數據必須是json對象,要是json字符串,必須先轉換成json對象才能作為datagrid的數據源。否則會出現異常:Cannot read property ‘length’ of undefined。
var str = '{"total":2,"rows":[{id:"1",name:"一"},{id:"2",name:"二"}]}'; var data = $.parseJSON(str); $('#dg').datagrid('loadData', data);
2、加載url方式獲取的數據
$('#dg').datagrid({ url:'datagrid_data2.json' });
3、Html中直接寫入
<table id='grid' class='easyui-datagrid' style='width:1100px;height:500px' title='用戶列表' iconCls='icon-table' rownumbers='true' fitColumns='true' singleSelect='true' toolbar='#toolbar' > <thead> <tr> <th field='file_name' width='50' align='center'>文件名稱</th> <th field='file_txt' width='70'align='center'>文件內容</th> <th field='file_path' width='70' align='center'>存儲位置</th> </tr> </thead> <tbody> <tr> <td>EST-1</td><td>FI-SW-01</td><td>Large</td> </tr> <tr> <td>EST-10</td><td>K9-DL-01</td><td>Spotted Adult Female</td> </tr> </tbody> </table>