纪念下Ext.grid.CheckColumn设可编辑状态

为了extjs这个功能,花了一天多,张把这个功能解决了;

上代码了.

引用的extjs2.2.1是ext/plugin/CheckColumn.js

 

 

  var win;
    var right_store;
    //value:catId
    //privTypes:'cat'
   function setRight(value,privTypes){
   	
     /// if(window) return window;
        var sm = new Ext.grid.CheckboxSelectionModel();
  // var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),sm, {header:'编号',dataIndex:'id'},{header:'名称',dataIndex:'name'},{header:'描述',dataIndex:'descn'}]);
  
        var saveas=new Ext.grid.CheckColumn({
    				header: '查阅',
		            dataIndex: 'saveas',
		           //  xtype: 'checkcolumn',
		            width: 70
		          });
	    	var enabled=new Ext.grid.CheckColumn({
    				header: '编辑',
    				  dataIndex: 'enabled',
		            width: 70
		           
    			});
    		var deleted=new Ext.grid.CheckColumn({
    				header: '删除',
    				  dataIndex: 'deleted',
		            width: 70
    			});
    		var granted=new Ext.grid.CheckColumn({
    				header: '授权',
    			    dataIndex: 'granted',
		            width: 70 
    			});
    			
     		  
        var cm = new Ext.grid.ColumnModel({
   	
   	
		columns : [sm,  {
			header : "id",
			dataIndex : "id",
			hidden : true
		}, {
			header : "对象名称",
			dataIndex : "relateName",
			width : 100
		}, {
			header : "类别",
			dataIndex : "type",
			width : 100,
		  renderer : function(value) {
				   if(value == "U" ||value == "ALL"){
						return "机构成员";
					}else if(value == "R"){
						return "角色";
					}else if(value == "D"){
						return "机构部门";
					}else if(value == "G"){
						return "组对象";
					}
				
				return value;
			}
		}, {
			header : "位置",
			dataIndex : "position",
			width : 100
		}, saveas,enabled,deleted,granted]});
		         
		   
		
	 initData = function() {
	var ds = new Ext.data.JsonReader({
		root : "list",
		fields:["id","relateName","type","position","saveas","enabled","deleted","granted"]
		/*fields : [{name:"id",type:"string"},
				  {name:"relateName",type:"string"},
				  {name:"type",type:"string"},
				  {name:"position",type:"string"},
				  {name:"saveas",type:"bool"},
				  {name:"enabled",type:"bool"},
				  {name:"deleted",type:"bool"},
				  {name:"granted",type:"bool"}]*/
	});

	var store = new Ext.data.Store({
		 autoDestroy: true,
	 	proxy : new Ext.data.HttpProxy({
			url : requestContextPath + "/desktopapp/getsharedres.do"
		}),
		reader : ds
	});
	store.on('beforeload', function(thiz, options) {
		
		thiz.baseParams["resId"] = value;
		thiz.baseParams["resType"] = 2;
		thiz.baseParams["loginWay"] = "web";
	});

	return store;
};
  right_store =initData();
   var grid = new Ext.grid.EditorGridPanel({
     region:'center',//居中
     store:right_store,//数据
     cm:cm,//列类似于数据库一样的结构
     sm:sm,//有多选框
       clicksToEdit: 1,
     loadMask:true,//加载loading条
     c     
    });
 
   right_store.load({param:{resId:value,resType:"2",loginWay:"web"}});
   
    win= new Ext.Window(
    {
    
      width:700,
      height:400,
      title:"权限设置",
       layout:'fit',
       items: [grid],
      buttons:[
      	
      		{text:'添加授权成员',
                handler:function(){
                  debugger;
		            var array =[];
						  array.push(value);
				       selectRight(Ext.encode(array),privTypes);
                }
               },
               	{text:'删除',
                handler:function(){
                  var b = grid.getSelectionModel().getSelections();
					if (b.length == 0) {
						Ext.Msg.alert("信息提示", "请选择要删除的记录!");
						return;
					}
					  
					 
				
					Ext.Msg.confirm("信息确认", "您确认要删除该记录吗?", function(c) {
						if (c == "yes") {
								for (var c = 0; c < b.length; c++) {
					            right_store.remove(b[c]);
				     	    }
						   
                }});
               }},
      			{text:'授权',
                handler:function(){
                	  debugger;
                	    var objList="";
                	    var str="";
                	    for(var k =0;k<right_store.data.length;k++){
                	        var obj =right_store.data.items[k].data;
                	          if(obj.type=="ALL"){
                	          	obj.type="U";
                	           }
                	             str=obj.id+","+obj.type+","+obj.saveas+","+obj.enabled+",1,1,"+obj.deleted+","+obj.granted+";";
                	            objList+=str;
                	    }
                	    
                     	Ext.Ajax.request({
								url : requestContextPath
										+ "/datapriv/saveExtDataprivGrants.do",
								params : {
									catId :value,
									delbefore:"1",
									resp:"2",
									extendparentpriv:"0",
									objList:objList
								},
								method : "post",
								success : function(response) {
									var text = Ext.util.JSON.decode(response.responseText);
									   var result =text.result;
									///  formPanel.getForm().setValues(result);
									///Ext.Msg.alert("信息提示", "成功删除所选记录!");
								 	
								}
							});
                 
                }
              },
              
              {text:'取消',
                handler:function(){
                  win.hide();
                }
               }
              ]
    });
    win.show();
    
   }
   

 

/desktopapp/getsharedres.do请求后的数据

{"list":[{"deleted":1,"enabled":1,"enddate":null,"granted":1,"id":"402880e5408f6bf801408f7312510002","memberId":"","position":"中山供电局","printpriv":1,"readonly":0,"relateName":"小燕","saveas":1,"startdate":null,"type":"U","visible":1}],"result":{"ResultCode":"0","Reason":""}}

 其中deleted这里可以表示1,0或true,false;

plugins:[saveas,enabled,deleted,granted]  //切记一定要写这句,否则将不可编辑

 

 

 

你可能感兴趣的:(column)