PDA

View Full Version : EditorGridPanel why isCellEditable function sends same request 2 times



iori0758
7 Jun 2011, 12:41 AM
I have a gridpanel ,I need to control whether is a cell editable,so I overried Ext.grid.CellSelectionModel

Ext.override(Ext.grid.CellSelectionModel, {
onEditorKey : function(field, e) {
// alert('go');
//alert( this.grid.activeEditor);

var k = e.getKey(), newCell, g = this.grid,l = g.lastEdit, ed = g.activeEditor;
var shift = e.shiftKey;
//Ext.log('k:' + k);

if(ed){
}else{
ed=l;
}

if (k == e.ENTER) {
e.stopEvent();
if(ed){
//ed.completeEdit();
}
if (shift) {
newCell = g.walkCells(ed.row, ed.col - 1, -1,
this.acceptsNav, this);
} else {
Ext.getCmp('search').focus(false, 200);
// newCell = g.walkCells(ed.row, ed.col + 1, 1,
// this.acceptsNav, this);
}
} else if (k == e.TAB) {
e.stopEvent();
ed.completeEdit();
if (this.moveEditorOnEnter !== false) {
if (shift) {
newCell = g.walkCells(ed.row - 1, ed.col, -1,
this.acceptsNav, this);
} else {
// alert('go');
// newCell = g.walkCells(ed.row + 1, ed.col, 1,
// this.acceptsNav, this);
newCell = g.walkCells(ed.row, ed.col + 1, 1,
this.acceptsNav, this);
}
}
}else if (k == e.LEFT) {
e.stopEvent();
ed.completeEdit();
newCell = g.walkCells(ed.row, ed.col - 1, -1,
this.acceptsNav, this);

}else if (k == e.RIGHT) {
e.stopEvent();
ed.completeEdit();
newCell = g.walkCells(ed.row, ed.col + 1, 1,
this.acceptsNav, this);

}else if (k == e.UP) {
e.stopEvent();
ed.completeEdit();
newCell = g.walkCells(ed.row - 1, ed.col, -1,
this.acceptsNav, this);

}else if (k == e.DOWN) {
e.stopEvent();
ed.completeEdit();
newCell = g.walkCells(ed.row + 1, ed.col, 1,
this.acceptsNav, this);

} else if (k == 107) {
change1();
} else if (k == e.ESC) {
ed.cancelEdit();
}
if (newCell) {
g.startEditing(newCell[0], newCell[1]);
}
}
});
..............
var gridPanel = new Ext.grid.EditorGridPanel
({
title:doctype=='RM'? '?????':"????",
cm:cm,
sm: new Ext.grid.CellSelectionModel({
singleSelect : true,
moveEditorOnEnter : true
}),
id:"grid_panel",
//renderTo:"grid_div",
split: true,
region: 'north',
stripeRows: true,
trackMouseOver : true,
clicksToEdit: 1,
store:newStore,
frame:true,
border:true,
layout:"fit",
plugins: summary,
pageSize:10000,
width:1000,
height:400,
view: new Ext.ux.grid.LockingGridView(),
viewConfig:{forceFit:true},
loadMask: {msg:'?????????...'},

.......
cm.isCellEditable = function(colIndex,rowIndex)
{

isSuccess = false;
var conn = Ext.lib.Ajax.getConnectionObject().conn;
conn.open("POST","EditSalesOrderLine",false);
conn.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
conn.send("style="
+Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get("??")+"&color="+Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get("??")
+"&size="+Ext.getCmp('grid_panel').getColumnModel().getDataIndex(colIndex)+"&actiontype=S" );
var responseArrays = Ext.util.JSON.decode(conn.responseText);
if(responseArrays.success){
isSuccess=true;
}

if(Ext.getCmp('availstore').getValue()==true){
if(Ext.getCmp('inventorygrid_panel').getStore().getCount()==0||Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get('??')!=Ext.getCmp('inventorygrid_panel').getStore().getAt(0).get('??')
||(Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get('??')==Ext.getCmp('inventorygrid_panel').getStore().getAt(0).get('??')
&&Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get('??')!=Ext.getCmp('inventorygrid_panel').getStore().getAt(0).get('??')))
newInventoryStore.load({params:{style:Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get("??"),
color:Ext.getCmp('grid_panel').getStore().getAt(rowIndex).get("??"),mWarehouseId:mWarehouseId,advanced:Ext.getCmp('advanced').getValue()}})
}
return isSuccess;

// return true;
};

when I clicked a cell with mouse,It send Ajax request one time ,It's ok,but when I use the 'left' or 'right' or 'up' or 'down' key ,it does not work,It send 2 request.I have no idea why it will happen.
If someone can help ,appreciate very much!
sorry for my poor english
Thanks in advance
iori

akramwahid
7 Jun 2011, 1:16 AM
please add the following config option to your data store and see whether it solve your problem

autoSave: false,

iori0758
7 Jun 2011, 4:31 PM
thanks akramwahid ,but it does not work,I add it to newStore,and restart the tomcat server,but it send 2 ajax request still!!

iori0758
10 Jun 2011, 6:43 PM
exactly to say when I use the 'left' or 'right' or 'up' or 'down' key,it execute function `cm.isCellEditable = function(colIndex,rowIndex)` 2 times,Is it a bug?