Hello!
I have a grid with a column “edn” and numberFomat:
----
gridPrecios.setNumberFormat(“0.00 €”, 2);
----
I have a row with a value 0 in column “edn”.
And this event onCellEdit:
----
if (stage == 1 && this.editor && this.editor.obj) {
this.editor.obj.select();
return true;
}
if (stage == 2) {
if (gridPrecios.cells(rowId, 2).getValue() == “”) gridPrecios.cells(rowId, 2).setValue(“0”);
alert (gridPrecios.cells(rowId, 2).getValue()); //shows empty string!!!
}
return true;
----
How can I have a value 0 in this cell and that it shows 0 in function getValue?
Thanks!
Bye
Hello,
insetad of if (gridPrecios.cells(rowId, 2).getValue() == “”) gridPrecios.cells(rowId, 2).setValue(“0”);
you can use the following approach:
if (gridPrecios.cells(rowId, 2).getValue() == “”) return “0.0”;
Please, see the dhtmlx.com/dhxdocs/doku.php? … oneditcell page for more details.
This is a bad solution because I have to validate more cells and I can’t return at this moment.
I need to put 0 in this cell and continue with calculations…
The provided approach is the only way to set custom value right after the editor is closed. What calculation do you want to execute ? Possibly it can be done before return command.
This is my code:
----
gridPrecios.attachEvent(“onEditCell”, function(stage, rowId, cellInd, newValue, oldValue){
if (stage == 2) {
if (gridPrecios.cells(rowId, 2).getValue() == “”) gridPrecios.cells(rowId, 2).setValue(“0”); //<----------------------------
if (cellInd == 0 || cellInd == 1) {
if (!validarEntero(gridPrecios.cells(rowId, cellInd).getValue())) {
gridPrecios.cells(rowId, cellInd).cell.style.backgroundColor = “#FE8383”;
return false;
} else {
gridPrecios.cells(rowId, cellInd).cell.style.backgroundColor = “”;
}
} else {
if (isNaN(gridPrecios.cells(rowId, cellInd).getValue())) {
gridPrecios.cells(rowId, cellInd).cell.style.backgroundColor = “#FE8383”;
return false;
} else {
gridPrecios.cells(rowId, cellInd).cell.style.backgroundColor = “”;
}
}
var celda0 = gridPrecios.cells(rowId, 0).getValue();
var celda1 = gridPrecios.cells(rowId, 1).getValue();
if (celda0 != “” && celda1 != “”) {
if (Number(celda0) >= Number(celda1))
return false;
}
var error = false;
if (celda0 != “” && celda1 != “”) {
gridPrecios.forEachRow(function(row){
if (gridPrecios.cells(row, 0).getValue() != “” && gridPrecios.cells(row, 1).getValue() != “” && row != rowId) {
if (celda1 >= Number(gridPrecios.cells(row, 0).getValue()) && celda0 <= Number(gridPrecios.cells(row, 1).getValue())) {
gridPrecios.cells(rowId, 0).cell.style.backgroundColor = “#FE8383”;
gridPrecios.cells(rowId, 1).cell.style.backgroundColor = “#FE8383”;
error = true;
} else {
gridPrecios.cells(rowId, 0).cell.style.backgroundColor = “”;
gridPrecios.cells(rowId, 1).cell.style.backgroundColor = “”;
}
}
});
}
if (error == true) {
return false;
}
var celda2 = ((gridPrecios.cells(rowId,2).getValue()=="")?“0”:gridPrecios.cells(rowId,2).getValue());
if (gridPrecios.cells(rowId,0).getValue() != “” && gridPrecios.cells(rowId,1).getValue() != “” && celda2 != “” && cellInd == 2) {
gridPrecios.addRow(“n”+contFila,",");
contFila ++;
}
}
return true;
});
----
In this case you can get value once, put it in some variable and manipulate with it. There is no need to call setValue and getValue methods sevaral times.
I remember that if in the oncelledit event didn’t return “true”, something failure. Can I be?
This event can return true(1), false(0) or some other value. Please, see details here:
dhtmlx.com/dhxdocs/doku.php? … oneditcell