Ext.onReady(function(){
var newFormWin;
var form1;
//表格处理
//Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';
Ext.QuickTips.init();
var sm = new Ext.grid.CheckboxSelectionModel(); //CheckBox选择列
var cm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(), //行号列
sm,
{header:'编号',dataIndex:'id'},
{header:'性别',dataIndex:'sex',renderer:function(value){
if(value=='1'){
return "男";
}else{
return "女";
}
}}, //增加性别,自定义renderer,即显示的样式,可以加html代码,来显示图片等。
{header:'名称',dataIndex:'name'},
{header:'描述',dataIndex:'memo'}
]);
var ds = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:ACTION_URL}),//调用的动作
reader: new Ext.data.JsonReader({
totalProperty: 'total',
root: 'list',
successProperty :'success'
},
[{name: 'id',mapping:'id',type:'string'},
{name: 'sex',mapping:'sex',type:'string'},
{name: 'name',mapping:'name',type:'string'},
{name: 'memo',mapping:'memo',type:'string'} //列的映射
])
});
var grid = new Ext.grid.GridPanel({
id: 'grid',
el: 'center',
region:'center',
title:'用户',
ds: ds,
sm: sm,
cm: cm,
bbar: new Ext.PagingToolbar({
pageSize: 10,
store: ds,
displayInfo: true,
displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
emptyMsg: "没有记录"
}) //页脚显示分页
});
//布局处理
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
new Ext.Viewport({
layout:'border',
items:[
{
xtype:'box',
region:'north',
el: 'north',
height:32,
title:'north'
},{
region:'south',
contentEl: 'south',
split:true,
height: 100,
minSize: 100,
maxSize: 200,
collapsible: true,
title:'South',
margins:'0 0 0 0'
},
grid
]
});
//el:指定html元素用于显示grid
grid.render();//Ext.getCmp('grid').render();//渲染表格
ds.load({params:{start:0, limit:10}}); //加载数据
grid.on("rowdblclick", function(grid) {
loadFormData(grid);
//alert(form1.reader);
});
// 载入被选择的数据行的表单数据
var loadFormData = function(grid) {
var _record = grid.getSelectionModel().getSelected();
if (!_record) {
Ext.example.msg('修改操作', '请选择要修改的一项!');
} else {
myFormWin();
form1.form.load( {
url : EDIT_ACTION_URL+'?sid='+ _record.get('id'),
waitMsg : '正在载入数据...',
success : function(form,action) {
Ext.example.msg('编辑', '载入成功!');
},
failure : function(form,action) {
Ext.example.msg('编辑', '载入失败');
}
});
}
};
var myFormWin = function() {
// create the window on the first click and reuse on subsequent
// clicks
if (!newFormWin) {
newFormWin = new Ext.Window( {
el : 'topic-win',
layout : 'fit',
width : 400,
height : 300,
closeAction : 'hide',
plain : true,
title : '窗口',
items : form1
});
}
newFormWin.show('New1');
};
form1 = new Ext.FormPanel( {
// collapsible : true,// 是否可以展开
labelWidth : 75, // label settings here cascade unless overridden
url : 'AddLevel.action',
frame : true,
title : '修改',
bodyStyle : 'padding:5px 5px 0',
width : 350,
waitMsgTarget : true,
//这个属性决定了load和submit中对数据的处理,list必须是一个集合类型,json格式应该是[]包含的一个数组
reader: new Ext.data.JsonReader({root:'list'},
[{name: 'id',mapping:'id',type:'string'},
{name: 'sex',mapping:'sex',type:'string'},
{name: 'memo',mapping:'memo',type:'string'}
]),
defaults : {
width : 230
},
defaultType : 'textfield',
items : [ {
fieldLabel : '编号',
name : 'id',
allowBlank : false
}, {
fieldLabel : '性别',
name : 'sex',
allowBlank : false
}, new Ext.form.TextArea( {
fieldLabel : '备注',
name : 'memo',
growMin : 234
})],
buttons : [ {
text : '保存',
disabled : false,
handler : function() {
if (form1.form.isValid()) {
form1.form.submit( {
url : 'AddLevel.action',
success : function(from, action) {
Ext.example.msg('保存成功', '添加级别成功!');
ds.load( {
params : {
start : 0,
limit : 30,
forumId : 4
}
});
},
failure : function(form, action) {
Ext.example.msg('保存失败', '添加级别失败!');
},
waitMsg : '正在保存数据,稍后...'
});
dialog.hide();
} else {
Ext.Msg.alert('信息', '请填写完成再提交!');
}
}
}, {
text : '取消',
handler : function() {
newFormWin.hide();
}
}]
});
});