Jump to content

how set datasource of tunidbgrid after dataset open


uniguisyriusz

Recommended Posts

First situation:

Unidbgrid.datasource = datasource1;

datasource1.dataset = fdquery1;

after fdquery1.open in unidbgrid I can see columns and rows with data.

Second situation:

unidbgrid.datasource = null;

datasource1.dataset = fdquery1;

fdquery1.open;

In afteropen of fdquery1:

unidbgrid.datasource = datasource1;

In this situation I can't see columns and rows, unidbgrid is "empty" until browser resize, form resize or click on refresh button of unidbgrid.

Calling unidbgrid.JSInterface.JSCall('view.refresh', []); in afteropen of fdquery works, but when I set fdquery.ResourceOptions.CmdExecMode := amAsync then exception "Attempt to access nil session reference" is raising.

Link to comment
Share on other sites

It takes a long time to open the query. I want to show a form with an empty grid, after running a query in the background (fdquery.ResourceOptions.CmdExecMode: = amAsync) I want to show data in the grid, so it can not be done in beforeOpen.

The second reason is two different queries, with different columns that I want to show in the same grid.

Link to comment
Share on other sites

1 hour ago, uniguisyriusz said:

>  It takes a long time to open the query

 

OK, May be :

1. DataSet  :

FdQuery1.FecthAll := False;
FdQuery1.Open

2. UnidbGrid :

WebOptions >  FetchAll : False
Paged                  :  True
PageSize               : 25

It's very fast even if you have 1 000 000 records !

Link to comment
Share on other sites

6 hours ago, uniguisyriusz said:

Calling unidbgrid.JSInterface.JSCall('view.refresh', []); in afteropen of fdquery works, but when I set fdquery.ResourceOptions.CmdExecMode := amAsync then exception "Attempt to access nil session reference" is raising.

In your stuation, something happening in background. You can't update user interface.

 

To be able to update it, you need an event from client side.

What i suggest is, add an unitimer to form and set enabled=False when query open. This timer will create events for you.

Link to comment
Share on other sites

Refresh on UniDbGrid?

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUIRegClasses, uniGUIForm, FireDAC.Stan.Intf,
  FireDAC.Stan.Option, FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS,
  FireDAC.Phys.Intf, FireDAC.DApt.Intf, FireDAC.Stan.Async, FireDAC.DApt,
  Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client, uniGUIBaseClasses,
  uniBasicGrid, uniDBGrid, uniButton, uniPanel, uniTimer, uniThreadTimer;

const
  WM_MY_MESSAGE = WM_USER + 0;

type
  TMainForm = class(TUniForm)
    FDQuery1: TFDQuery;
    UniDBGrid1: TUniDBGrid;
    DataSource1: TDataSource;
    UniButton1: TUniButton;
    UniTimer1: TUniTimer;
    procedure FDQuery1AfterOpen(DataSet: TDataSet);
    procedure UniButton1Click(Sender: TObject);
  private

  public
    { Public declarations }
  end;

function MainForm: TMainForm;

implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication;

function MainForm: TMainForm;
begin
  Result := TMainForm(UniMainModule.GetFormInstance(TMainForm));
end;

procedure TMainForm.FDQuery1AfterOpen(DataSet: TDataSet);
begin
  DataSource1.DataSet := FDQuery1;
  UniDBGrid1.DataSource := DataSource1;
  UniTimer1.Enabled := false;
  //UniDBGrid1.JSInterface.JSCall('view.refresh', []);
end;

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  FDQuery1.Open();
end;

initialization
  RegisterAppFormClass(TMainForm);

end.

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