In the extjs grid, we often need to add an image status or button to summarize the methods we have used:
1. Status representation:
The code copy is as follows:
renderer:function(value){
if(value==0){
return "<img src='images/icons/cancel.png'>";
}else if(value==1){
return "<img src='images/icons/accept.png'>";
}
return value;
}
Add renderer identification status in columns columns, the rendering is as follows:
http://images.cnitblog.com/blog/489550/201304/19103818-94991d9869a6458e8a568efdea6081b5.png
2. Event handling:
Add onclick event to img directly:
The code copy is as follows:
<img style="cursor:pointer;" onclick="updateRecord(/''+sn+"@"+ss+"@"+record.get("standardId")+'/');" src=/'${ ctx}/img/edit.png/' alt=/'Detailed Maintenance/' title=/'Detailed Maintenance/'>'
Events are passing the required data over.
Another way is to add a cell click event to grid:
The code copy is as follows:
listeners: {
cellClick: viewDoc
}
function viewDoc(grid, rowIdx, colIdx, e) {
var action = e.getTarget().value;
}
This way you can get the clicked cell and add event processing.
3. You can use 'actioncolumn' to add picture button
The code copy is as follows:
{header:'Certificate of Conformity',sortable:false,width:80,align:'center',scope:this,
xtype:
'actioncolumn',
items: [{
icon: '${ctx}/img/details.png',
tooltip: 'Show certificate of conformity',
handler : function(grid, rowIndex, colIndex) {
var record = grid.getStore().getAt(rowIndex);
//. . .
}
]}
This also allows you to add images in the grid cell.