Search code examples
javascriptgriddhtmlxdatagridcomboboxcolumn

Fill a cell with a value only if combo box option is selected


I am developing a web app on dhtmlx. I have a grid which has 3 columns. The first one is combo and the other 2 editables. all the rows are blank in the beginning. the user must select one option from combo and type an amount on one of each other two. when he types an amount on one the other is disabled and vice versa. when he clicks on the next row the moment after he selects an option on combo i want the amount of the last cell editable to fill the cell of the second column of the new row. for example if i have in (1,1) 100 i want after the combo selection on row 2 the (2,2) to be filled with 100 as well. I tried this code but it only fills (2,2) when i click and edit (1,1) for a second time. What am i doing wrong?

myGrid.attachEvent("onEditCell", function (stage, rId, cInd, nValue, oValue) {
                    if (stage === 2 && myGrid.cells(rId, 1).getValue() !== "0" && myGrid.cells(rId, 0).getValue() !== "") {
                        var x = myGrid.cells(rId, 1).getValue();
                        myGrid.cellById(rId, 2).setDisabled(true);
                        if (myGrid.cells(rId + 1, 0).getValue() !== "") {
                            myGrid.cells(rId + 1, 2).setValue(x);
                            myGrid.cellById(rId + 1, 1).setDisabled(true);
                            return true;
                        }
                        return true;
                    } else if (stage === 2 && myGrid.cells(rId, 2).getValue() !== "0" && myGrid.cells(rId, 0).getValue() !== "") {
                        var x = myGrid.cells(rId, 2).getValue();
                        myGrid.cellById(rId, 1).setDisabled(true);
                        if (myGrid.cells(rId + 1, 0).getValue() !== "") {
                            myGrid.cells(rId + 1, 1).setValue(x);
                            myGrid.cellById(rId + 1, 2).setDisabled(true);
                            return true;
                        }
                        return true;
                    }
                });

the cells with value must be both editable at the end.


Solution

  • If I got you right, You may try to do something like: http://snippet.dhtmlx.com/b32986bf1