PDA

View Full Version : how to set value for grid cell on beforeedit



prnandaece
2 Feb 2012, 3:10 AM
how to set value for grid cell on beforeedit function?

I want to evaluate some expression on beforeedit . The evaluated value will be disappeared when focusing a cell (i.e beforeedit). it will be appeared after out of cell focus (i.e afteredit).

please some one help to fix this issue

Thanks,

My code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Bcs</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<link rel="icon" href="images/bcs.ico" />
<script type="text/javascript" src="extjs/ext.js"></script>
<script type="text/javascript" src="extjs/ext-all-debug.js"></script>
<script type="text/javascript">

Ext.onReady(function(){

Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['qty', 'rate', 'amt'],
data:{'items':[{"qty":10, "rate":13},{"qty":20, "rate":13},{"qty":30, "rate":14}]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{header: 'Qty', dataIndex: 'qty',
editor: {
xtype: 'numberfield',
id:'qty-id',
allowBlank: false
}},
{header: 'Rate', dataIndex: 'rate',
editor: {
xtype: 'numberfield',
id:'rate-id',
allowBlank: false
}
},
{header: 'Amount', dataIndex: 'amt',
editor: {
xtype: 'numberfield',
id:'amt-id',
allowBlank: false
}}
],
selType: 'cellmodel',
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1,
listeners : {

'beforeedit' : function(e, data, fields, record) {


if(e.grid.columns[(e.colIdx)].editor==undefined)
{

var GridCrntObj=e.grid.columns[(e.colIdx)].field;

}
else
{

var GridCrntObj=e.grid.columns[(e.colIdx)].editor;

}
if(GridCrntObj.id=="amt-id")
{

e.grid.store.data.items[e.rowIdx].data['amt']=(e.grid.store.data.items[e.rowIdx].data['qty']*e.grid.store.data.items[e.rowIdx].data['rate'])



}

e.grid.getView().refreshNode(e.rowIdx);



},

'afteredit':function(e, data, fields, record) {



}

}

})
],
height: 120,
width: 303,
renderTo: Ext.getBody()
});

});


</script>

</head>
<body>

</body>

</html>

masoud_tamizy
2 Feb 2012, 5:11 AM
you can use blur event (onblur) in your listener ...


blur:function(me){
var code=me.getValue();
alert (code);
}

prnandaece
2 Feb 2012, 5:26 AM
here i am using cell editor . expression should be evaluated when focusing to the cell.

anyway thanks your reply.