Ext.onReady(function() {
Ext.BLANK_IMAGE_URL = '../resources/images/default/s.gif';
Ext.QuickTips.init();
function formatDate(value) {
//var date = new Date(value);
return value ? date.dateFormat('Y-m-d H:i:s') : '';
}
var sm = new Ext.grid.CheckboxSelectionModel({checkOnly : true});
var cm = new Ext.grid.ColumnModel([sm, {
id : 'ID',
header : '编号',
dataIndex : 'ID',
align : 'center',
width : 110,
hidden : true
}, {
header : '名称',
dataIndex : 'name',
align : 'center',
width : 150,
editor : new Ext.form.TextField({})
}, {
header : "时间",
dataIndex : 'time',
width : 120,
align : 'center',
renderer : formatDate,
editor : new Ext.ux.form.DateTimeField({
fieldLabel : '时间',
id : 'time',
name : 'time',
width : 130,
height : 30,
allowBlank : false,
blankText : '时间不能为空',
editable : false,
value : new Date()
})
}]);
var record = Ext.data.Record.create([{
name : 'ID',
type : 'string'
}, {
name : 'name',
type : 'string'
}, {
name : 'time',
type : 'date',
dateFormat : 'Y-m-d H:i:s'
}]);
var store = new Ext.data.Store({
autoLoad : false,
pruneModifiedRecords : true, //每次Store加载后,清除所有修改过的记录信息
proxy : new Ext.data.HttpProxy({
url : 'list.action',
method : 'POST'
}),
baseParams : {
pageNo : 0,
pageSize : 10
},
paramNames : {
start : "pageNo",
limit : "pageSize"
},
reader : new Ext.data.JsonReader({
totalProperty : 'totalCount',
root : 'results'
}, record)
});
store.load();
var tbar = new Ext.Toolbar({
items : [{
text : '新增',
iconCls : 'add',
handler : add
}, '-', {
text : '保存',
iconCls : 'save',
handler : save
}, '-', {
text : '删除',
iconCls : 'remove',
handler : remove
}]
});
var bbar = new Ext.PagingToolbar({
pageSize : 10,
store : store,
displayInfo : true,
lastText : "尾页",
nextText : "下一页",
beforePageText : "当前",
prevText : "上一页",
firstText : "首页",
refreshText : "刷新",
afterPageText : "页,共{0}页",
displayMsg : '数据从第{0}条 - 第{1}条 共{2}条数据',
emptyMsg : '没有数据'
});
var grid = new Ext.grid.EditorGridPanel({
id : "myGrid",
title : '信息维护',
renderTo : 'grid',
sm : sm,
cm : cm,
store : store,
clicksToEdit : 1,
loadMask : {
msg : '正在加载数据,请稍侯……'
},
autoScroll : true,
autoWidth : true,
autoHeight : true,
stripeRows : true,
viewConfig : {
forceFit : true
},
tbar : tbar,
bbar : bbar
});
grid.render();
function add() {
var initValue = {
ID : "",
name : "",
time : new Date()
};
var recode = store.recordType;
var p = new recode(initValue); // 根据上面创建的recode 创建一个默认值
grid.stopEditing();
store.insert(0, p);// 在第一个位置插入
grid.startEditing(0, 1);// 指定的行/列,进行单元格内容的编辑
}
function save() {
var modified = store.modified;
Ext.Msg.confirm("警告", "确定要保存吗?", function(button) {
if (button == "yes") {
var json = [];
Ext.each(modified, function(item) {
json.push(item.data);
});
if (json.length > 0) {
Ext.Ajax.request({
url : "save.action",
params : {
data : Ext.util.JSON.encode(json)
},
method : "POST",
success : function(response) {
Ext.Msg.alert("信息","数据保存成功!",function() {
store.reload();
});
},
failure : function(response) {
Ext.Msg.alert("警告","数据保存失败,请稍后再试!");
}
});
} else {
Ext.Msg.alert("警告", "没有任何需要更新的数据!");
}
}
});
}
function remove() {
var selModel = grid.getSelectionModel();
if (selModel.hasSelection()) {
Ext.Msg.confirm("警告", "确定要删除吗?", function(button) {
if (button == "yes") {
var recs = selModel.getSelections();
var list = [];
for (var i = 0; i < recs.length; i++) {
var rec = recs[i];
list.push("'" + rec.get('ID') + "'");
}
Ext.Ajax.request({
url : "delete.action",
params : {
data : list.join(',')
},
method : "POST",
success : function(response) {
Ext.Msg.alert("信息","数据删除成功!", function() {
store.reload();
});
},
failure : function(response) {
Ext.Msg.alert("警告","数据删除失败,请稍后再试!");
}
});
}
});
} else {
Ext.Msg.alert("错误", "没有任何行被选中,无法进行删除操作!");
}
}
});
后台:
public String list() throws Exception {
String sql = "select ID,name,time from Info";
String rs= infoService.getJSONBySQL(sql, page);
String jsonString = "{totalCount:" + page.getTotal() + ",results:" + rs+ "}";
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
response.getWriter().print(jsonString);
return null;
}
public String save() throws Exception {
String data = request.getParameter("data");
JSONArray array = JSONArray.fromObject(data);
Object[] list = array.toArray();
for (int i = 0; i < list.length; i++) {
Map<String, String> map = (Map<String, String>) list[i];
Info info = new Info();
info.setId(map.get("ID"));
info.setName(map.get("name"));
info.setTime(map.get("time"));
if (null != info.getId() && info.getId().length() > 0) {
infoService.upate(info);
} else {
infoService.save(info);
}
}
response.getWriter().write("SUCCESS");
return null;
}
public String delete() throws Exception {
String ids = request.getParameter("data");
infoService.delete(ids);
response.getWriter().write("SUCCESS");
return null;
}
分享到:
相关推荐
此文档是可编辑表格Ext.grid.EditorGridPanel的说明以及示例的源代码,放到eclipse里面即可运行,显示出效果!
因为项目的需求,实现一个可以编辑的tree,在网上找了一个牛人写的控件.Ext.ux.maximgb.tg.EditorGridPanel 把源码下载下来以后 不能运行,自己根据给出的列子,另写了一个小程序.不过并没有与数据库交互.
NULL 博文链接:https://tonylian.iteye.com/blog/1735525
ext 数据对象的定义 EditorGridPanel的使用 ext读取xml ext对各种数据格式的支持
NULL 博文链接:https://zxf-noimp.iteye.com/blog/629629
73、Ext.grid.EditorGridPanel类 ……… 62 74、Ext.grid.PropertyGrid类 …………… 65 1、Ext类 addBehaviors(Object obj) : void 对选择的元素 应用事件侦听器,事件名以@附加在结尾,例如 addBehaviors({ ...
右键菜单的资料,代码已经详细描写。请仿照文件中所描述即可使用,不限于EXT4.0以上版本使用。
为了解决这个问题需要在EditorGridPanel的ColumnModel中显示ComboBox的地方使用renderer属性,重新渲染,方法如下: 代码如下: //部门列表 var comboxDepartmentStore = new Ext.data.Store({ proxy: new Ext.data....
NULL 博文链接:https://fourfire.iteye.com/blog/355853
1、Ext类 ………………………………… 2 2、Array类 …………………………… 4 3、Number类 …………………………… 4 4、...73、Ext.grid.EditorGridPanel类 ……… 62 74、Ext.grid.PropertyGrid类 …………… 65
1.界面修改(css style): Extjs中界面风格与我们产品本身的风格有很大不同,从边框、... 属性的作用(About Ext.grid. GroupingView, EditorGridPanel): Extjs的grid功能强大,如排序、隐藏列或移动列等,这些都有一些属
感谢 Ericzhen 远离颠倒梦想,蕴籍无上清凉 这里引用它的资源 仅作分享 http://www.cnblogs.com/Ericzhen/archive/2012/06/11/2545186.html
22)可编辑表格EditorGridPanel 23)窗口基本应用 24)窗口分组 25)对话框 26)与服务器交互 27)Record 28)Store 29)TreePanel基本使用 30)使用树控件TreeNode 31)使用树控件TreeLoader 32)自定义TreeLoader
详细介绍GridPanel各项属性,ExtJS 普通表格:Ext.grid.GridPanel属性详解
因为前段时间有两个专案要用到extjs技术,所以自己学了一段...grid,tree,显示树信息的TreePanel、用于显示表格的GridPanel及EditorGridPanel,还有代表应用程序窗口的Ext.Window,与数据库交付,希望对初学者带来帮助
Grid EditorGridPanel 使用本地store Toolbar工具菜单创建 分页工具栏创建 Window 弹出处理window窗口(模态窗口) MessageBox show(报错窗口、保存提示、选择窗口) alert prompt 实用工具类 JS异常捕捉 ...
1 A framework apart 2 Back to the basics 3 Events, Components, and Containers ...8 The EditorGridPanel 9 Taking root with Trees 10 Toolbars and Menus 11 Drag and drop with Widgets
….36 6.2 可编辑的表格EditorGridPanel……….………………………………………………………………………..…….41 6.3 与服务器交互……….………………………………………………………………………………...