Stage 2 in editcell executed twice when focus moves

I am curently using DHTMLX tree grid ,and doing some basic validations in my application
using onEditCell

My requirement is simple, as follows:
USer enters account number in cell - account number should be numeric, if not throw
a validation alert message “Account number should be numeric”, and set the focus
back to the cell and higlight the row, following is my code

   function doOnCellEdit(stage, rowId, cellInd,newValue,oldValue) {
     if(stage==2){
	 if(isNumeric(mygrid.cells(rowId,cellInd).getValue())){
	        alert("Account should be numeric");
                    rownum=mygrid.getRowIndex(selectedRow);
	        mygrid.selectRow(rownum);//highlight the row
	        mygrid.selectCell(rownum,selectedCellIndex,false,false,true,false); //put the cursor back to the cell
		status=false
		 }else{
		        status=true;
		 }   

     }
 }

I enter a non numeric value , and move my focus to somewhere else in the grid, i select some other cell, at this point for stage=2 onEditcell function, the alert message is displayed. Now as soon as mygrid.selectCell gets executed, what i do observe
is the onEditCell function again switches to stage 2 and calls the same validation function above twice , again the validation
message gets displayed the second time and finally the cursor or focus goes back to the cell.

This problem only happens when i click somewhere else in the grid, i see alerts coming twice.The first time it goes into
stage=2 when i select somewhereelse on the grid(editing ended), validation function gets called, and alert gets displayed
now focus should get displayed back to the cell, inorder to do that- i call SelectCell which edit mode set to true,
but this time i goes to Stage 0 then 1 and then to stage 2???I wish to know why should stage 2 be executed twice
when i move my focus from the cell when i click somewhere else on the grid,

This problem does not happen if i move focus anywhere on the page outside the grid.

Currently i am using onRowSelect function , i call the selectedCell method in its call back function, and use some flag
variable to avoid the validation alert to be displayed twice.

I am also using onTab event to activate validations on tab, that works great

Please explain why stage=2 is invoked twice when i click somewhere else on the grid?

Normally it must not occur, but if you are using single-click edit or similar functionality it may happens. ( you call selectCell from onEdit event, and if it switches another cell to the edit state it may cause non-expected reaction, grid will tries to close currently active editor )

You can try to isolate you call as

function doOnCellEdit(stage, rowId, cellInd,newValue,oldValue) {
if(stage==2){
if(isNumeric(mygrid.cells(rowId,cellInd).getValue())){
alert(“Account should be numeric”);
rownum=mygrid.getRowIndex(selectedRow);
window.setTimeout(function(){
mygrid.selectRow(rownum);//highlight the row
mygrid.selectCell(rownum,selectedCellIndex,false,false,true,false);
},1);