Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by martin macpherson on Jan 21, 2010 07:54
open dhtmlx forum
oneditcell reverts new value to old value

Hi

I have a dhtmlxgrid that is being created from an html table.Code is below.

What is happening is that the inclusion of the event function for onEditCell causes the new value that has been entered to be replaced with the old value.

If i remove the event function completely, the values are updated and displayed as expected.

couple of bits to explain..

the propertyarray is being used to marry up a cell with an ident that i am using in my ajax call.
colSort will be a combination of str,int or date.
colVal will be a combination of ed, calck and dhxCalendarA
I have a button elsewhere on the form that allows the user to copy the whole grid to the clipboard as a csv.

inclusions.....
<link rel="STYLESHEET" type="text/css" href="js/dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.css"/>
<link rel="stylesheet" type="text/css" href="js/dhtmlx/dhtmlxGrid/codebase/skins/dhtmlxgrid_dhx_skyblue.css"/>
<script src="js/dhtmlx/dhtmlxGrid/codebase/dhtmlxcommon.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/dhtmlxgrid.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/dhtmlxgridcell.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_srnd.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_start.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_selection.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/ext/dhtmlxgrid_nxml.js"></script>
<script src="js/dhtmlx/dhtmlxCalendar/codebase/dhtmlxcalendar.js"></script>
<link rel="STYLESHEET" type="text/css" href="js/dhtmlx/dhtmlxCalendar/codebase/skins/dhtmlxcalendar_yahoolike.css"/>
<script src="js/dhtmlx/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_dhxcalendar.js"></script>
<script src="js/dhtmlx/dhtmlxGrid/codebase/excells/dhtmlxgrid_excell_calck.js"></script>

Now the actual grid code...

var propertyArray=new Array(<%=columnListSB.toString()%>);
var grid=new dhtmlXGridFromTable("QueryResults");
//grid.init();
grid.setSkin("dhx_skyblue");
grid.enableCellIds(true);
grid.enableSmartRendering(true);
grid.setImagePath("/js/dhtmlxGrid/codebase/imgs/");
grid.enableAutoWidth(true);
grid.enableAutoHeight(true);
grid.setColSorting("<%=colSort.toString()%>");
grid.setColTypes("<%=colVal.toString()%>");
var cl=0;
var propertyTypeStr='ro,ro';
grid.setDateFormat("%d/%m/%Y");
grid.setNumberFormat("$0,000");
grid.enableCSVHeader(true);
grid.csv.cell="\t";
grid.attachEvent("onEditCell",function(stage,rId,cInd,newValue,oldValue)
{
if(stage==0)
{
grid.editCell();
}
if(stage==2 && oldValue!=newValue)
{
grid.editStop();
grid.cellById(rId, cInd).setValue(newValue);
grid.selectRow(rId, false, false, true);
grid.setRowColor(rId,"grey");
var selectProperty=propertyArray[cInd];
var selectContainer= grid.cellById(rId, 0).getValue();
var newValue=escape(newValue);
var oldValue=escape(oldValue);
new Ajax.Request(someurl);
//grid.cellById(rId, cInd).setValue(newValue);

}
}
);

I cant figure out why it isnt working. If i do an alert where the last commented out grid.cellbyid.setvalue call is the cells value is as i would expect. So it seems something is happening after that to revert the value.

Think i am missing something. Help!!
Answer posted by Alex (support) on Jan 21, 2010 08:30

onEditCell event handler should return true to confirm editing result. Moreover ther shouldn't be editCell() call in the stage 0.

grid.attachEvent("onEditCell",function(stage,rId,cInd,newValue,oldValue){
/*some code here*/

return true

})