Jump to content
uniGUI Discussion Forums
Stemon63

update dataset events in UniDBgrid...

Recommended Posts

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

Share this post


Link to post
Share on other sites

you try in queryfield onvalidate  ?

 

or

create a field type fkCalculated

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

I think he means,dataset.oncaculated only fired when leave unidbgrid current edited row and focus(change to) another row

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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;

Share this post


Link to post
Share on other sites

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!!

Share this post


Link to post
Share on other sites

Hi,

 

Can you make a simple testcase for this, by indicating what and how you wanted?

Share this post


Link to post
Share on other sites

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;

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites

You can use after edit cell unidbgrid call

dataset.post;

 

for force call calculated method use this combination

 

dataset.Edit;

dataset.Cancel;

Share this post


Link to post
Share on other sites

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....

Share this post


Link to post
Share on other sites

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;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×