日期:2014-05-16  浏览次数:20427 次

extjs4 增删改查grid
Ext.onReady(function(){
	Ext.QuickTips.init();
			Ext.define('Group', {
		       extend: 'Ext.data.Model',
		       fields: [
		           'groupId','name', 'contents'
		       ]
		    });
			var store_grid_group = Ext.create('Ext.data.Store', {
		        pageSize: 4,
		        model: 'Group',
		        remoteSort: true,
		        proxy: {
		            type:'ajax',
		            url:'../limits/listgroupbypage!listGroupByPage',
		            reader:{
						type:'json',
						root:'data',
						totalProperty: 'totalCount'
					},
		           simpleSortMode: true
		        },
		        autoLoad:true
		    });
		    
		    
		    var form = new Ext.FormPanel({
				layout: {
		            type: 'vbox',
		            align: 'stretch'
		        },
		        frame: true,
		        border: false,
		        url: '../limits/saveqx!addGroup',
		        buttonAlign:'center',
		        bodyPadding: 10,
		        defaultType: 'textfield',
		        fieldDefaults: {
		            labelAlign: 'left',
		            labelWidth: 100,
		            labelStyle: 'font-weight:bold'
		        },
		        //默认元素属性设置
		        items: [{
		            name: 'name',
		            fieldLabel: '权限组名称',
		            allowBlank: false
		        },{
		            xtype: 'textareafield',
		            name:'contens',
		            fieldLabel: '权限组描述',
		            margins: '0',
		            allowBlank: false
		       }],
		       buttons:[{
		       		text:'保存',
		       		handler:function(){
		       			if (this.up('form').getForm().isValid()) {
		                    form.submit({
			                    success: function(form, action) {
			                    	form.reset();
			                    	win.hide();
			                    	store_grid_group.load();
			                    },
			                    failure: function(form, action) {
			                        Ext.Msg.alert('Failed');
			                    }
		                	});
		                }
					}
		       },{
					text:'放弃',handler:function(){
						 this.up('form').getForm().reset();
		                 this.up('window').hide();
					}
		       }]
		     })
		     var form_edit = new Ext.FormPanel({
				layout: {
		            type: 'vbox',
		            align: 'stretch'
		        },
		        frame: true,
		        border: false,
		        url: '../limits/editgroup!updateGroup',
		        buttonAlign:'center',
		        bodyPadding: 10,
		        defaultType: 'textfield',
		        fieldDefaults: {
		            labelAlign: 'left',
		            labelWidth: 100,
		            labelStyle: 'font-weight:bold'
		        },
		        //默认元素属性设置
		        items: [{
		            name: 'groupId',
		            fieldLabel: '编号',
		            hidden: true
		        },{
		            name: 'name',
		            fieldLabel: '全选组名称',
		            allowBlank: false
		        },{
		            xtype: 'textareafield',
		            name:'contents',
		            fieldLabel: '权限组描述',
		            margins: '0',
		            allowBlank: false
		       }],
		       buttons:[{
		       		text:'修改',
		       		handler:function(){
		       			if (this.up('form').getForm().isValid()) {
		                    form_edit.submit({
			                    success: function(form, action) {
			                    	form.reset();
			                    	win_edit.hide();
			                    	store_grid_group.load();
			                    },
			                    failure: function(form, action) {
			                        Ext.Msg.alert('Failed');
			                    }
		                	});
		                }
					}
		       },{
					text:'放弃',handler:function(){
						 this.up('form').getForm().reset();
		                 this.up('window').hide();
					}
		       }]
		     })
		    var win = Ext.create('widget.window', {
		    	layout:'fit',
		        title: '添加',
		        closable: false,
		        closeAction: 'hide',
		        width: 400,