Extjs grid column里添加button等html标签,并增加点击事件

Extjs里有个actioncolumn,但actioncolumn只能添加一系列button,不能既有字又有button

如何能在column里增加html标签,并给button添加事件呢?

1. 首先,在column里重写renderer方法,方法里拼html语句

View里主要代码如下:

 columns: [{
                    header: 'Complex column',
                    width: 90,
                    renderer: function(value, cellmeta, record) {
                    	var display="Text";
                    	display+='
'; display+=' class="add" src="extjs/resources/themes/images/spinner.gif" alt="Add" />'; display+='class="edit" src="extjs/resources/themes/images/spinner.gif" alt="Edit">'; display+='class="delete" src="extjs/resources/themes/images/spinner.gif" alt="Delete">'; return display; } }]

2. 在Controller里添加事件

init : function() {
		console.log('The window was rendered');
		this.control({
			'ResultPage > grid[id=resultGrid]':{
				cellclick:this.cellClick
			}
		});
	},
	
	cellClick : function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) {
		console.log("cell clicked");
		var add = e.getTarget('.add');
		var edit = e.getTarget('.edit');
		var del = e.getTarget('.delete');
		if (add) {
			console.log("click add");
		}
		if(edit){
			console.log("click edit");
		}
		if(del){
			console.log("click del");
		}
	}

这里有一点要注意,html里用class标识,然后在事件里用getTarget('.add')去寻找。我尝试在html里用id,getTarget(id)找不到。

你可能感兴趣的:(Extjs)