Extjs多图标表格操作按钮列组件实现

写此组件是看了joffice中的表格列中将操作用图标在一个列中实现,但看了源码他们采用的是在renderer中用拼接html标签实现,这样就难维护,不好使用,而且点击图片执行操作的时候作用域是指向整个window,并不能或用很不好的方式去获取表格本身这个对象,于是自己写了个,呈现的效果是一样,但使用更方便,作用域好控制,先晒一张效果图,在此展示下效果:

 

实现代码:

/**
 * 按钮列按钮表格控件
 * @class Ext.ux.grid.MultiImageBtnColumn
 * @extends Ext.util.Observable
 * @author hanfei
 * @cfg buttons @type array or Object  
 * @example :
 * buttons :[{text : '查看',
			cls : "btn-task",
			scope : this,
			handler : function(v,m,r){alert(r.get("key")+this.getTitle())}
		}]
需加入css样式		
div button {
	border: none;
	cursor: pointer;
	width: 16px;
	height: 16px;
}

.btn-task {
	background: url(task.gif) no-repeat !important;
}
 */
Ext.ux.grid.MultiImageBtnColumn = Ext.extend(Ext.util.Observable,{
			constructor : function(config){
			Ext.apply(this, config);
			Ext.ux.grid.MultiImageBtnColumn.superclass.constructor.call(this, config);
		},
		renderer : function(v){
			var str= "" ;
			if(!this.buttons){
				return "no buttons";
			}
			if(Ext.isArray(this.buttons)){//如果是数组
				for(var i= 0;i<this.buttons.length;i++){
					var id = Ext.id();//button id
					var item = this.buttons[i];
					Ext.ux.grid.ColumnHandlers.add({
						id: id,
						fn: item.handler,
						scope: item.scope || this,//设置作用域
						params: Array.prototype.slice.call(arguments,0)
					});
					if(!item.hiddenFn  || item.hiddenFn.apply((item.scope || this),Array.prototype.slice.call(arguments,0))){
						str+='<button id="' + id + '" title="'+item.text+' " value=" " style="border: none;cursor: pointer;width: 16px;height: 16px;" class="'+item.cls+'" οnclick="(' + this.clickDelegate + ').call(this, event)"></button>&nbsp;'
					}
				}
				return str ;
			}else if(Ext.isObject(this.buttons)) {//
					var id = Ext.id();//button id
					var item = this.buttons;
					Ext.ux.grid.ColumnHandlers.add({
						id: id,
						fn: item.handler,
						scope: item.scope || this,//设置作用域
						params: Array.prototype.slice.call(arguments,0)
					});
					if(!item.hiddenFn  || item.hiddenFn.apply((item.scope || this),Array.prototype.slice.call(arguments,0))){
						str= '<button id="' + id + '" title="'+item.text+' " value=" " style="border: none;cursor: pointer;width: 16px;height: 16px;"  class="'+item.cls+'" οnclick="(' + this.clickDelegate + ').call(this, event)"></button>&nbsp;'
					}
					return str;
			}
		},
		clickDelegate : function(e){
			var handler = Ext.ux.grid.ColumnHandlers.get(this.id);
			e = Ext.EventObject.setEvent(e);
			if(handler){
				handler.fn.apply(handler.scope, handler.params.concat(e));
			}
		}
	});

 调用方式只需在定义表格列的时候像如下方式调用即可:

[new Ext.ux.grid.MultiImageBtnColumn({
						header : '操作项',
						dataIndex : 'userId',
						width : 80,
						buttons : [{text : '编辑',
								cls : "btn-writeFlow",
								scope : this,
								handler : this.editUser
							},{
								text :"删除",
								cls : "btn-viewFlow",
								scope : this,
								handler : this.delUser
							},{
								text :"接收任务",
								cls : "btn-endFlow",
								scope : this,
								hiddenFn :function(v,m,r){//此方法用于是否显示该图标按钮
									return Ext.isEmpty(r.get("assignee"));
								},
								handler : this.reciveTask
							}]
		
		})

 到此一个完整的表格列组件开发完成。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值