Using DataGrid Master/Detail with Aurelius

Hi, i want use your DataGrid together with Aurelius. I want a master/detail config, both Grids were feed by a AureliusDataset. The detail dataset can have many rows, so i use a criteria which is build in the AfterScroll event of the MasterDataset.

There is no master/detail link within the datasets. If i use both grids independent from each other, everything works as expected. If i link the master TMSFNCDataGridDatabaseAdapter with the secondary grid in the DetailControl property, there is no way getting this secondary control visible at runtime. So, is there a way doing this or using objects lists directly ?

-> The criteria i use to fetch the data:

procedure TdmSmartDocs.DocStoresDSAfterScroll(DataSet: TDataSet);
var store := DocStoresDS.Current;
if Assigned(Store) then
begin
vclServerFRM.StoreToForm(Store);
documentsList := appManager.ObjectManager.Find
.CreateAlias('Stores', 's')
.Add(Linq['s.Id']=store.id)
.OrderBy('Saved')
//.Skip(PageIdx * PageSize)
.Take(PageSize)
.RemovingDuplicatedEntities
.List;

  DocumentsDS.SetSourceList(documentsList);
  DocumentsDS.Active := True;

end;

Can you provide some more details on "not visible", the detailcontrol should be linked at runtime, before opening the master, or at designtime. It's a means to display the control as a sub-grid, with expand collapse capabilities.

I've tried both ways. Linking the grid at runtime, also at designtime. The same is true for the Datasources. MyI guess is, the failure comes from the way i control the secondary datasource/dataset. Closing/Opening the detail dataset within the AfterScroll event, without having any information for the grid how to link this, seems not to be working.

Anyway i do it manually now. I mainly use some code you posted here, only a bit nicer.

function TvclServerFRM.CloseGrid (aRow : Integer) : Boolean;
begin
result := False;
if ExpandedRowIndex >= 0 then
begin
result := True;
DocumentsData.Visible := False;
DataGrid.SplitCell(MakeCell(0, ExpandedRowIndex + 1));
DataGrid.DeleteRow(ExpandedRowIndex + 1);
if ARow = ExpandedRowIndex then
begin
ExpandedRowIndex := -1;
Exit; // Toggle off
end
else if ARow > ExpandedRowIndex then
Dec(ARow); // Anpassung, weil eine Zeile entfernt wurde
ExpandedRowIndex := -1;
end;
end;

procedure TvclServerFRM.ExpandGrid(aRow : Integer) ;
begin
// Wenn bereits ein Detail geöffnet ist, dann zuerst entfernen
DataGrid.InsertRow(ARow + 1);
DataGrid.MergeCells(0, ARow + 1, DataGrid.ColumnCount, 1); // Eine große Detailzeile
DataGrid.Controls[0, ARow + 1] := DocumentsData;
DocumentsData.Visible := True;
DataGrid.AutoSizeRow(ARow + 1);
//DataGrid.ControlAligns[0, 2] := gcaClient;
DataGrid.ControlAligns[0, ARow + 1] := gcaClient;
ExpandedRowIndex := ARow;
end;

procedure TvclServerFRM.OpenOrClose;
begin
if not CloseGrid(aRow) then
ExpandGrid(aRow);
end;

ExpandedRowIndex is a global (inside the applocation object) Variable wich takes the expandedRow or -1 if now row is expanded.

This works. It is not as smooth as it could be, but for the moment ok.

1 Like

Ok, thanks for sharing the code.