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>
来自网上资料
自己实际测试的结果:
<body>
<div class="easyui-layout" data-options="fit:true">
<div data-options="region:'north'" style="width: 100%;height: 10%">
</div>
<div data-options="region:'center',title:'测试数据记录列表'">
<table id="datagrid" class="easyui-datagrid" style="width: 100%; height: 100%"
url="/select"
toolbar="#dgtoolbar"
pagination="true"
pageSize="10"
pageList="[25,15,10]"
rownumbers="false"
fitColumns="true"
singleSelect="true"
loadMsg="正在查询...">
<thead>
<tr>
<th field="cb" checkbox="true" align="center"></th>
<th data-options="field:'id',align:'center'" width="5%">编号</th>
<th data-options="field:'user',align:'center'" width="25%">测试人员</th>
<th data-options="field:'path',align:'center'" width="45%">文件路径</th>
<th data-options="field:'time',align:'center'" width="25%">测试时间</th>
</tr>
</thead>
</table>
</div>
</div>
<!--<script type="text/javascript">-->
<!--$(document).ready(-->
<!--$.post("/select",-->
<!--function(data){-->
<!--console.log(data);-->
<!--$("#datagrid").datagrid('loadData', data);-->
<!--}-->
<!--)-->
<!--);-->
<!--</script>-->
</body>
后端:
@RequestMapping(value="/select")
public Map getdata(){
Map resultMap=new HashMap();
List<TMemory>list=meoryService.getData();
resultMap.put("total",list.size()+1);
resultMap.put("rows",list);
return resultMap;
}
实现的效果:
实现效果比较ok!