本文实例为大家分享了EasyUI DataGird的使用方法,供大家参考,具体内容如下
1. html代码
<table
id="grid"
style="width: 940px"
title="用户操作"
data-options="iconCls:'icon-view'">
</table>2.显示

3.js代码
// 页面加载后显示表数据
$(function() {
var queryData = {};// 可添加一些预设条件
InitGrid(queryData);// 初始化Datagrid表格数据
});// 实现对DataGird控件的绑定操作
function InitGrid(queryData) {
$('#grid').datagrid({ // 定位到Table标签,Table标签的ID是grid
url : 'getNoticesByUserId',// 指向后台的Action来获取当前用户的信息的Json格式的数据
title : '公告管理',
iconCls : 'icon-view',
height : 650,
width : function() {
return document.body.clientWidth
},// 自动宽度
pagination : true,
rownumbers : true,
sortName : 'title', // 根据某个字段给easyUI排序
pageSize : 20,
sortOrder : 'asc',
remoteSort : false,
idField : 'id',
queryParams : queryData, // 异步查询的参数
columns : [ [ {
field : 'ck',
width : '1%',
checkbox : true
}, {
title : '标题',
field : 'title',
width : '9%',
sortable : true,
halign : 'center'
}, {
title : '发布人',
field : 'userName',
width : '10%',
sortable : true,
halign : 'center'
}, {
title : '内容',
field : 'content',
width : '50%',
sortable : true,
halign : 'center',
sortable : false
}, {
title : '创建日期',
field : 'createDate',
width : '20%',
sortable : true,
halign : 'center',
align : 'center',
sortable : false
} ] ],
toolbar : [ {
id : 'btnAdd',
text : '添加',
iconCls : 'icon-add',
handler : function() {
ShowAddDialog();// 实现添加记录的页面
}
}, '-', {
id : 'btnEdit',
text : '修改',
iconCls : 'icon-edit',
handler : function() {
ShowEditDialog();// 实现修改记录的方法
}
}, '-', {
id : 'btnDelete',
text : '删除',
iconCls : 'icon-remove',
handler : function() {
Delete();// 实现直接删除数据的方法
}
} ] });
};
4.Json数据










