1、在页面中获取
<%--
Created by IntelliJ IDEA.
User: Dong
Date: 2020/4/27
Time: 16:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/ztree3.5/zTreeStyle.css" type="text/css">
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/ztree3.5/jquery.ztree.all-3.5.js"></script>
</head>
<body>
<table class="easyui-datagrid">
<thead>
<tr>
<th data-options="field:'itemid',width:80">编号</th>
<th data-options="field:'productid',width:100">姓名</th>
<th data-options="field:'listprice',width:80,align:'right'">手机号</th>
</tr>
</thead>
<tr>
<td>A01</td>
<td>李三</td>
<td>110</td>
</tr>
<tr>
<td>A01</td>
<td>李三</td>
<td>110</td>
</tr>
</table>
</body>
</html>
2、在JSON文件中获取
<%--
Created by IntelliJ IDEA.
User: Dong
Date: 2020/4/27
Time: 16:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<link rel="stylesheet" href="${pageContext.request.contextPath}/js/ztree3.5/zTreeStyle.css" type="text/css">
<script type="text/javascript"
src="${pageContext.request.contextPath}/js/ztree3.5/jquery.ztree.all-3.5.js"></script>
</head>
<body>
<table class="easyui-datagrid" data-options="url:'${pageContext.request.contextPath}/demo/stafftest.json'">
<thead>
<tr>
<th data-options="field:'id',width:80">编号</th>
<th data-options="field:'name',width:100">姓名</th>
<th data-options="field:'age',width:80,align:'right'">手机号</th>
</tr>
</thead>
</table>
</body>
</html>
stafftest.json:
[
{"id":"001","name":"李大","age":"13912345678","haspda":"1","deltag":"0","standard":"10-20公斤","station":"杭州分部"},
{"id":"002","name":"李二","age":"13912345678","haspda":"1","deltag":"0","standard":"10-20公斤","station":"杭州分部"},
{"id":"003","name":"李二","age":"13912345678","haspda":"1","deltag":"0","standard":"10-20公斤","station":"杭州分部"},
{"id":"004","name":"李二","age":"13912345678","haspda":"1","deltag":"0","standard":"10-20公斤","station":"杭州分部"}
]
3、通过JS动态创建datagrid
- 代码:
<script type="text/javascript"> $(function () { $('#grid').datagrid({ url:'/Bos/json/stafftest.json', columns:[[ {field:'id',title:'编号',width:100,checkbox:true}, {field:'name',title:'名字',width:100}, {field:'age',title:'手机',width:100,align:'right'} ]], toolbar: [{ iconCls: 'icon-edit', text:'Edit', handler: function(){alert('编辑按钮')} },'-',{ iconCls: 'icon-help', text:'Help', handler: function(){alert('帮助按钮')} },'-',{ text:'删除', handler: function(){} },'-',{ text:'修改', handler: function(){} }]
}); }); </script> js的方式渲染datagrid <table id="grid"></table> |