ext 左右表格数据互相移动

1 篇文章 0 订阅
var chooseSm = new Ext.grid.CheckboxSelectionModel({singleSelect: false});  
	var allSm = new Ext.grid.CheckboxSelectionModel({singleSelect: false});
	
	// 移除岗位
	var removeJobFunction = function(){
		var selRows = allGrid.getSelectionModel().getSelections();
		unstationStore.add(selRows);
		hasstationStore.remove(selRows);
	}
	
	// 添加岗位
	var addJobFunction = function(){
		var selRows = chooseGrid.getSelectionModel().getSelections();
		hasstationStore.add(selRows);
		unstationStore.remove(selRows);
	}
	
	// 保存岗位设置至数据库
	var saveJobFunction = function() {
       	var jobjson= [];
       	var hasstationRecord = hasstationStore.getRange();
		if(hasstationRecord.length>0){
            Ext.each(hasstationRecord, function(hasstationRecord){
            	jobjson.push(hasstationRecord.data);
           });
       	}
		Ext.Ajax.request({
        	waitMsg: '正在提交数据',
        	waitTitle: '提示',
        	url: 'personnel_updateJob.action',
        	method: 'post',
        	params:{
        		userid : userid,
        		departmentid : departmentid, 
        		organizeid : organizeid,
        		jobjson : Ext.encode(jobjson)
        	},
        	success:function(response,action){  
        		Ext.Msg.alert('提示','保存成功!');
        		personnelStore.load({
        			params : {
        				limit : pageSize,
        				realname : Ext.getCmp('ser_realname').getValue(),
        				code : Ext.getCmp('ser_code').getValue()
        			}
        		});
        		userJobWin.hide();
            },  
            failure:function(){
                Ext.Msg.alert('提示','保存失败!');  
            }
    	});
	}
	
	var chooseGrid = new Ext.grid.GridPanel({
		title : '未分配的岗位',width : 250,region : 'west',
		stripeRows : true,autoScroll : true,loadMask : true,
		store : unstationStore,sm : chooseSm,
		cm : new Ext.grid.ColumnModel({
			defaultSortable : 'true',
			columns : [chooseSm,{header : '岗位名称',dataIndex : 'station',width : 200}]
		})
	});
	
	var buttonPanel = new Ext.Panel({
		region : 'center',layout : 'column',
		items : [{xtype : 'spacer',columnWidth : 1,height : 150},
				{xtype : 'spacer',columnWidth : .05,height : 25},
				{xtype : 'button',columnWidth : .9,anchor:'95%',text : '《',height : 25,handler : removeJobFunction},
				{xtype : 'spacer',columnWidth : .05,height : 25},
				{xtype : 'spacer',columnWidth : 1,height : 5},
				{xtype : 'spacer',columnWidth : .05,height : 25},
				{xtype : 'button',columnWidth : .9,anchor:'95%',text : '》',height : 25,handler : addJobFunction,},
				{xtype : 'spacer',columnWidth : .05,height : 25},
				{xtype : 'spacer',columnWidth : 1,height : 5},
				{xtype : 'spacer',columnWidth : .05,height : 25},
				{xtype : 'spacer',columnWidth : .05,height : 25}]
	});
	
	var allGrid = new Ext.grid.GridPanel({
		title : '所属岗位',width : 250,region : 'east',
		stripeRows : true,autoScroll : true,loadMask : true,
		store : hasstationStore,sm : allSm,
		cm : new Ext.grid.ColumnModel({defaultSortable : 'true',
			columns : [allSm,{header : '岗位名称',dataIndex : 'station',width : 200}]
		})
	});
	
	var userJobWin = new Ext.Window({
		frame : true,iconCls : 'user-add',title : '岗位配置',
		constrain : true,layout:'fit',modal: true,width:600,height:400,
        closeAction:'hide',plain: true,
        items: [
        {
        	xtype : 'panel',width: 400,layout : 'border',
        	items : [chooseGrid,buttonPanel,allGrid]   
        }],
        tbar : [{
        	typeAhead: true,triggerAction: 'all',lazyRender:true,anchor:'98%',
	    	xtype : 'combo',fieldLabel :'机构',emptyText:'请选择机构',editable : true,//禁止编辑
			displayField:'name',valueField: 'id',id : 'organizeid',store: organizeStore,
			listeners:{
                "select":function(combo,record,index){
                	Ext.getCmp('departmentid').clearValue();
                	organizeid = combo.getValue();
                	departmentStore.load({
            			params : {organizeid : organizeid}
            		});
                }
            }
		},{
			typeAhead: true,triggerAction: 'all',lazyRender:true,anchor:'98%',mode:'local',
	    	xtype : 'combo',fieldLabel :'部门',emptyText:'请选择部门',editable : true,//禁止编辑
			displayField:'name',valueField: 'id',id : 'departmentid',store: departmentStore,
			listeners:{
                "select":function(combo,record,index){
                	departmentid = combo.getValue();
                	unstationStore.load({
                		params : {
                			userid : userid,
                			departmentid : departmentid,
                			organizeid : organizeid
                		}
                	});
                	hasstationStore.load({
                		params : {
                			userid : userid,
                			departmentid : departmentid,
                			organizeid : organizeid
                		}
                	});
                }
            }
		},'->','-',{
			xtype : 'button',text : '取消',iconCls: 'cancle',
			handler : function () {
				userJobWin.hide();
			}
		},'->','-',{
			xtype : 'button',text : '保存',iconCls: 'save',
			handler : function () {
				saveJobFunction();
			}
		}]
    });
	
	// 岗位配置
	function editJobFunction () {
		if(grid.getSelectionModel().getCount()>0){
			var selRecord = grid.getSelectionModel().getSelected();
			userid = selRecord.data['userid'];
			Ext.getCmp('organizeid').clearValue();
			Ext.getCmp('departmentid').clearValue();
			hasstationStore.removeAll();
			unstationStore.removeAll();
			userJobWin.show();
		} else {
			Ext.Msg.alert('提示','请选择一条记录!');  
		}
	}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值