bruno-pere Posted April 18, 2013 Posted April 18, 2013 Hi! I'm using ExtJs 4.2 because onvalidateedit has a bug in ExtJs 4.1.1 where e.value shows the originalvalue instead of the new value. I'm trying to change the value of column 7 based on the value of column 6, per example: function OnValidateedit(editor, e, eOpts){ if (e.colIdx == 6) { e.record.set('6', e.value); e.record.set('7', e.value * 10); } } This code works. But when I go to the next record then the value of column '7' goes back to previous value. I tried e.record.store.sync() and save(), but it is not working properly. Using server side code is working correctly BUT I need this to work client side. Any tips? Thx! Bruno Quote
bruno-pere Posted April 18, 2013 Author Posted April 18, 2013 SOLVED. This change (client side validation instead of server side) speeds up user operation on slow connections. Only works in ExtJs 4.2.1.744 beta. ExtJs 4.1.1a has a bug where e.value shows the originalvalue instead of the new value. ExtJs 4.2.0 has many bugs. Problems in Grid navigation, per example. When the cell is changed and the RETURN key is pressed the grid does no navigate anymore using UP/DOWN/LEFT/RIGHT. Client side validation in ExtEvents of grid. function OnValidateedit(editor, e, eOpts) { function compareValue(a,comp,b,decimals) { if (!decimals) decimals = 3; var multiplier = Math.pow(10,decimals); // multiply to do integer comparison instead of floating point a = Math.round(a * multiplier); b = Math.round(b * multiplier); switch (comp) { case ">": return (a > b ); case ">=": return (a >= b ); case "<": return (a < b ); case "<=": return (a <= b ); case "==": return (a == b ); } return null; } //alert( compareValue(1,'==',1.0001).toString() ); // sair se não houve alteração - leave if the values are the same if (e.value == e.originalValue) { return; } // checar se estamos em colunas que podem ser alteradas - check if we are in allowed columns (I use readonly in gui too) if (e.colIdx != 7 && e.colIdx != 8 && e.colIdx != 9) { e.cancel = true; alert( 'Somente as colunas estoque, quantidade CX e quantidade KG/UN podem ser alteradas.' ); // only some columns can be changed return; } // pegar os valores - get the values try { var peso = parseFloat(e.record.get('6'));//.replace(/\s/g, "").replace(",", ".")); var estoq = parseFloat(e.record.get('7'));//.replace(/\s/g, "").replace(",", ".")); var val = parseFloat(e.value.replace(/\s/g, "").replace(",", ".")); var cod_loja = e.record.get('3'); } catch (e) { e.cancel = true; alert( 'Número inválido.' ); // invalid number (any) return; } //parseFloat(str.replace(/\s/g, "").replace(",", ".")); // validar - validations /*if ( (cod_loja == null) || (cod_loja == '') ) { e.cancel = true; alert( 'Este produto não possui código na loja. Caso queira pedi-lo, entre em contato com o faturamento da Extrafruti.' ); return; }*/ if ( compareValue(val,'<',0,5) ) { e.cancel = true; alert( 'O valor não pode ser negativo.' ); // the value can't be less then zero return; } if ( e.colIdx==9 && compareValue(val,'<',peso,2) ) { e.cancel = true; alert( 'A quantidade em KG/UN não pode ser menor que o peso da caixa.' ); // validation return; } if ( e.colIdx==9 && compareValue(val % peso,'>',0,5) ) { e.cancel = true; alert( 'A quantidade em KG/UN deve ser múltipla do peso da caixa.' ); // validation return; } if ( e.colIdx==8 && compareValue(val % 1,'>',0,2) ) { e.cancel = true; alert( 'A quantidade em CX deve ser inteira. Não é possível pedir meia caixa.' ); // validation return; } // gravar CX e KG convertendo de para - save values of columns 8 and 9 (multiplied by peso or divided by peso) if (e.colIdx == 8) { e.record.set('8', val); e.record.set('9', val * peso); } else if (e.colIdx == 9) { e.record.set('9',val); e.record.set('8',val / peso); } // envie a atualização ao servidor - tell the server to update in the dataset ajaxRequest( MainForm.grid1, 'ValidateEdit', ['qtd='+e.record.get('9'),'qtdCX='+e.record.get('8')] ); } And save to dataset: procedure TMainForm.grid1AjaxEvent(Sender: TComponent; EventName: string; Params: TStrings); var qtd,qtdCX: string; begin if EventName='ValidateEdit' then begin qtd := Params.Values['qtd']; qtdCX := Params.Values['qtdCX']; if (UpperCase(qtd)<>'UNDEFINED')and(UpperCase(qtdCX)<>'UNDEFINED') then begin if not (AdoQuery1.State in ([dsEdit, dsInsert])) then AdoQuery1.Edit; AdoQuery1QUANTIDADE_CX.Value := qtdCX; AdoQuery1QUANTIDADE.Value := qtd; end; end; end; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.