Best practice for dispaying master detail

Hi,


On a form I have a  TWebDBGrid1 (the master grid) connected to a TXDataWebDataSet via a TWebDataSource.  

I also have a second grid to show the detail data for a selected row in the master grid with its own TWebDataSource and TXDataWebDataSet

My problem is to get the active record in the master TWebDBGrid1 after scrolling to a new record.
It seems the OnDataChange event of a TWebDataSource does not fire upon scrolling and the AfterScoll event of a TXDataWebDataSet fires for all the records even if you scroll only one record.

The only way I'm able to display detail records of a master record is to use a button with code like this:
procedure TForm1.WebButton2Click(Sender: TObject);
var
  Code: string;
begin
  Code := #39 + xdsDepartments.FieldByName('DeptCode').AsString + #39;

  xdsSTKMaster.QueryString := '$filter=DeptCode eq ' + Code;
  xdsSTKMaster.Load;
end;

Regards,

Nols Smit

Hello Nols,

We don't see such behavior here. Maybe you can send us a test project that reproduces the problem (preferable connecting to your server in the cloud). Here AfterScroll works normally, and there you could perform the mentioned request.

I tested it again on the music server and the OnDataChange event of the TWebDataSouce does not fire with record changes.  My form and source:



unit uMainUnit;

interface

uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, Data.DB, WEBLib.DB, WEBLib.DBCtrls, Vcl.Controls, Vcl.Grids,
  XData.Web.JsonDataset, XData.Web.Dataset, XData.Web.Connection, Vcl.StdCtrls, WEBLib.StdCtrls;

type
  TMainForm = class(TWebForm)
    XDataWebConnection1: TXDataWebConnection;
    XDataWebDataSet1: TXDataWebDataSet;
    WebDBGrid1: TWebDBGrid;
    WebDBNavigator1: TWebDBNavigator;
    WebDataSource1: TWebDataSource;
    XDataWebDataSet1Artist: TXDataWebEntityField;
    XDataWebDataSet1Id: TIntegerField;
    XDataWebDataSet1Name: TStringField;
    WebButton1: TWebButton;
    WebLabel1: TWebLabel;
    procedure XDataWebConnection1Connect(Sender: TObject);
    procedure WebButton1Click(Sender: TObject);
    procedure WebDataSource1DataChange(Sender: TObject; Field: TField);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.WebButton1Click(Sender: TObject);
begin
  XDataWebConnection1.Connected := true;
end;

procedure TMainForm.WebDataSource1DataChange(Sender: TObject; Field: TField);
begin
  WebLabel1.Caption := XDataWebDataSet1.FieldByName('Artist').AsString + ' ' + XDataWebDataSet1.FieldByName('Name').AsString;
end;

procedure TMainForm.XDataWebConnection1Connect(Sender: TObject);
begin
  XDataWebDataSet1.Load;
end;

end.

Hi Nols, we will check what is going on with OnDataChange. Maybe there is an issue.

But you can use AfterScroll, did you have a problem with it?

We found the issue with OnDataChange, next version will have a fix for it. In the meanwhile you can use AfterScroll event.

AfterScroll works OK for a TWebClientDataSet but not for a TXDataWebDatset - it fires for all the records

Can you please explain what do you mean by "fires for all the records"? Can you provide steps to reproduce the issue?

When you visually move to the next/previous record, AfterScroll  iterates thru all records in the TXDataWebDatset

Is this with TMS WEB Core v1.4?
If not, can you please try with TMS WEB Core v1.4?

Tested it on v1.4 and the problem remains