Method to add a picture state or button to the Extjs grid


In the extjs grid, we often need to add a picture state or button. Summarize the methods we have used:

I. status expression:


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 the status of renderer in columns. The effect diagram is as follows:

http://images.cnitblog.com/blog/489550/201304/19103818-94991d9869a6458e8a568efdea6081b5.png

Ii. Event handling:

Add the onclick event to img directly:


<img style="cursor:pointer;" onclick="updateRecord(''+sn+"@"+ss+"@"+record.get("standardId")+'');" src='${ctx}/img/edit.png' alt=' Details of maintenance ' title=' Details of maintenance '>'

An event is the passing of 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;

}

This will give you the cells to click on, and then add the event handling.

You can use ‘actioncolumn’ to add a picture button


{header:' Certificate of approval ',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 also allows you to add pictures to the grid cell.