We often need to add a picture status or button in the extjs grid. Let’s summarize the methods we have used:
1. Status representation:
renderer:function(value){
if(value==0){
return "
";
}else if(value==1){
return "
";
}
return value;
}
Add renderer identification status in columns. The effect is as follows:
http://images.cnitblog.com/ blog/489550/201304/19103818-94991d9869a6458e8a568efdea6081b5.png
2. Event handling:
Add onclick event directly to img:
'
The event is to pass the required data.
Another way is to add a cell click event to the grid:
listeners: {
cellClick: viewDoc
}
function viewDoc(grid, rowIdx, colIdx, e) {
var action = e.getTarget(). value;
}
In this way, you can get the clicked cell and then add event processing.
3. You can use 'actioncolumn' to add image buttons
{header:'certificate',sortable:false,width:80,align:'center',scope:this,
xtype:
'actioncolumn',
items : [{
icon : '${ctx}/img/details.png',
tooltip : 'Display certificate',
handler : function(grid, rowIndex, colIndex) {
var record = grid.getStore().getAt(rowIndex);
//. . .
}
]}
This way you can also add pictures to grid cells.