Jump to content

Immediately Post Record to Database (Grid)


bruno-pere

Recommended Posts

Hi!

 

I am trying to post the grid record immediately to the database after a cell has been edited.

 

Actually, the record is posted to the database only after a scroll.

 

I've been playing with ExtEvents of the grid like OnAfterEdit, OnValidateEdit and some procedures of the ExtJs store like commitChanges() and save() but without success.

 

Does anyone know how to do that?

 

Thx!

 

Bruno

Link to comment
Share on other sites

The same question arises when editing data grid, made ​​with Timer.

Perhaps this is what you need.

 

procedure DataVirtualTableAfterEdit(DataSet: TDataSet);
begin
 inherited;
 UniTimer.Enabled := True;
end;

//
procedure UniTimerTimer(Sender: TObject);
begin
 inherited;

 UniTimer.Enabled := False;
//
   DataVirtualTable.DisableControls;
   ...
   DataVirtualTable.edit;
   ...
   DataVirtualTable.post;
   ...
       
   DataVirtualTable.Next;
//
 DataVirtualTable.EnableControls;    
end;

Link to comment
Share on other sites

Worked here... but i appreciate a better solution...

 

 

In the Grid ExtEvents -> OnValidateEdit

 

function OnValidateedit(e)

{

ajaxRequest(UniFrameCons.GridCons,

'ValidateEdit',

['val='+e.value]);

}

 

 

In the Grid OnAjaxEvent

 

procedure TUniFrameCons.GridConsAjaxEvent(Sender: TComponent; EventName: string;

Params: TStrings);

begin

if EventName='ValidateEdit' then

begin

if not (AdoQueryCons.State in ([dsEdit, dsInsert])) then

AdoQueryCons.Edit;

AdoQueryConsQUANTIDADE.Value := Params.Values['val'];

AdoQueryCons.Post;

end;

end;

 

 

ATTENTION: This code works for me because ONLY one column can be edited in this grid. If you have more columns to be edited you should change this code.

 

Bye!

 

Bruno

Link to comment
Share on other sites

  • 1 month later...

Updating...

 

 

To know what column sent the ValidateEdit and post immediately...

 

 

Declare

 

type

    THackGrid = class(TUniDBGrid);

 

 

 

And in the grid ajaxevent

 

procedure TUniFramePed.gridIPAjaxEvent(Sender: TComponent; EventName: string;
  Params: TStrings);
var
  col: integer;
begin
  if EventName='ValidateEdit' then
  begin
    col := THackGrid(GridIP).CurrCol;
    if (col=8)or(col=9) then
    begin
      if not (AdoQueryIP.State in ([dsEdit, dsInsert])) then
        AdoQueryIP.Edit;
      if col=8 then // caixa
        AdoQueryIPQUANTIDADE_CX.Value := Params.Values['val']
      else
      if col=9 then // kg
        AdoQueryIPQUANTIDADE.Value := Params.Values['val'];
      AdoQueryIP.Post;
    end;
  end;
end;

 

 

 

OnValidateEdit in ExtEvents remains the same, but attention to uppercase or lowercase in the grid name. JavaS will recognize only the exact name of the component in the form. Like:

 

function OnValidateedit(e)
{
  ajaxRequest(UniFramePed.gridIP,
   'ValidateEdit',
   ['val='+e.value]);
}

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...