Stemon63 Posted May 7, 2018 Share Posted May 7, 2018 Hi, in UniDbGrid, I need to update and calculate field WITHOUT change row for posting data to dataset, but during normal editing, on cell navigate;For example: Quantity * Price must update field TotalRow on change Quantity or Price. Now I can see updated value only on changing row (with automatic post). There is a method or funtion for update the underline record fields values on changing cell? Thanks in advance, Stefano Quote Link to comment Share on other sites More sharing options...
Wilton Ergon Posted May 7, 2018 Share Posted May 7, 2018 you try in queryfield onvalidate ? or create a field type fkCalculated Quote Link to comment Share on other sites More sharing options...
Stemon63 Posted May 8, 2018 Author Share Posted May 8, 2018 Hi Wilton, the problem is not related to calculate fields, but WHEN data is transfered from grid to dataset. It seems that values are send to dataset only when user change row...I need that updates values are send on change column or on any change in cell editor. Thanks Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 8, 2018 Share Posted May 8, 2018 Hi, Hi Wilton, the problem is not related to calculate fields, but WHEN data is transfered from grid to dataset. It seems that values are send to dataset only when user change row...I need that updates values are send on change column or on any change in cell editor. Thanks Can you make a simple testcase for this, by indicating what and how you wanted? Quote Link to comment Share on other sites More sharing options...
zhyhero Posted May 8, 2018 Share Posted May 8, 2018 I think he means,dataset.oncaculated only fired when leave unidbgrid current edited row and focus(change to) another row Quote Link to comment Share on other sites More sharing options...
Stemon63 Posted May 8, 2018 Author Share Posted May 8, 2018 Yes, zhyhero. I want to calculate also on change a single cell (with refresh of other columns) after tab or enter key. It's normal in a desktop application. Thanks Quote Link to comment Share on other sites More sharing options...
Beginner Posted May 8, 2018 Share Posted May 8, 2018 I have found a bit of a hack solution. Maybe there is a more direct way of doing it, but this is what works for me: Create a helper for the TFDDataSet class as follows: type TFDDataSetHelper = class helper for TFDDataSet public procedure InternalCalc; end; implementation uses FireDAC.DatS; { TFDDataSetHelper } procedure TFDDataSetHelper.InternalCalc; var oRow: TFDDatSRow; begin oRow := GetRow(ActiveBuffer); oRow.ForceChange(rsCalculating); end; and use the unit then, after any of the fields change that the internal calculated fields rely on, call: TFDDataSet(dataset).InternalCalc; Quote Link to comment Share on other sites More sharing options...
Stemon63 Posted May 9, 2018 Author Share Posted May 9, 2018 Hi, yes,thanks, but the problem is in client side of UNIGUI. Values, in standard unigui dbeditors, are assigned to Db fields on exit (or changed value) of dbeditor.In UniDbgrid, instead, values are assigned on change row, and not on exit (or changed value) of a single cell (or editor assigned to column).I understand that server must be called only when need, and calling frequently (cell by cell) must be dangerous, but there are common situations where calc, compute, totals and control must be done during editing of a row, and the DBrecord on server must be updated "as soon as" for refresh values... If there is a method for transfer grid's record values in DB records (the same that is called on change row when edit) I can use it on "edit" event in ExtJs.... Thanks!! Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 9, 2018 Share Posted May 9, 2018 Hi, Can you make a simple testcase for this, by indicating what and how you wanted? Quote Link to comment Share on other sites More sharing options...
Stemon63 Posted May 10, 2018 Author Share Posted May 10, 2018 Hi, Yes I have little test. testUnigui.zip Quote Link to comment Share on other sites More sharing options...
Sherzod Posted May 10, 2018 Share Posted May 10, 2018 Hi, Hi, Yes I have little test. You can follow these instructions, for example for total field: 1. FDTABLEtotal -> FieldKind = fkCalculated 2. FDTABLE -> OnNewRecord procedure TMainForm.FDTABLENewRecord(DataSet: TDataSet); begin FDTABLE.FieldByName('total').AsFloat := 0; end; 3. FDTABLE -> OnCalcFields procedure TMainForm.FDTABLECalcFields(DataSet: TDataSet); begin with FDTABLE do FieldByName('total').AsFloat := FieldByName('price').AsFloat * FieldByName('quantity').AsInteger; UniDBGrid1.RefreshCurrentRow(); end; Quote Link to comment Share on other sites More sharing options...
Stemon63 Posted May 11, 2018 Author Share Posted May 11, 2018 Hi Delphi Developer, Thank you for help. But the problem is another....this is very restrictive to dataset calculate fields.I known very well dataset logic (i use delphi from release 1), but i want focus to Unigui and ExtJs and not dataset calcfields. My example show a little demo of simply calculate fields in a grid. But, in production I cannot use 300 calculate fields or use events on dataset side; For 90% of times those calculate fields can be forced or modified by user, so I need to calculate in functions or procedure where are a mix datasets and variables and also "forced" checkboxs, for example , (my calculation are very complex, for tax and account applications and involve many datasets at once). So, this approach is very very restrictive. My focus is another direction.I want to say simply how launch my Delphi procedures (with or without dataset involved) from Unidbgrid events AFTER CELL COLUMN CONTENT IS MODIFIED (and related delphi field value are already updated). There are no events for this? There is no an "onEditValuechange" in UniDbGrid? Thanks a lot. :-) Stefano Quote Link to comment Share on other sites More sharing options...
Beginner Posted May 11, 2018 Share Posted May 11, 2018 You can use after edit cell unidbgrid call dataset.post; for force call calculated method use this combination dataset.Edit; dataset.Cancel; Quote Link to comment Share on other sites More sharing options...
Stemon63 Posted May 14, 2018 Author Share Posted May 14, 2018 Hi Beginner, thanks a lot. But where is "after edit cell" event?All Extjs events (cell) work well when you navigate (select, etc.) , but not when you in "editing" state; I need to edit cell, press tab, and edit the next cell (without press Enter), with its value already refreshed (calculate). And naturally without post and edit continuosly dataset.... Quote Link to comment Share on other sites More sharing options...
zhyhero Posted May 14, 2018 Share Posted May 14, 2018 Hi Beginner, thanks a lot. But where is "after edit cell" event? All Extjs events (cell) work well when you navigate (select, etc.) , but not when you in "editing" state; I need to edit cell, press tab, and edit the next cell (without press Enter), with its value already refreshed (calculate). And naturally without post and edit continuosly dataset.... I test these code with 1.10.0.1456,maybe work for you. write code in UniDBGrid's OnSetCellValue event procedure TMainForm.UniDBGrid1SetCellValue(Sender: TObject; ACol, ARow: Integer; AField: TField; var Value: Variant); begin self.UniDBGrid1.DataSource.DataSet.Edit; self.UniDBGrid1.DataSource.DataSet.FieldByName(self.UniDBGrid1.Columns.Items[Acol].FieldName).Value:=Value; self.UniDBGrid1.DataSource.DataSet.Post; end; Quote Link to comment Share on other sites More sharing options...
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.