easyui datagrid加载数据的三种方式

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!

  • 5
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值