Delphi UniGUI PagedGrid with summary
UniGUI allows you to split the dataset into pages, for this you need to enable WebOptions -> Paged := true in the grid properties
It might look like this
The previous method of calculating the final results will not work, because the sum will be calculated only for those records that are visible. So, what to do in this case? To do this, we just need to calculate them in another place, for example like this
procedure TMainForm.CalcTotals;
var
B : TBookmark;
begin
if not FInited then Exit;
ClientDataSet1.DisableControls;
B := ClientDataSet1.GetBookmark;
try
GTotal := 0;
GTotalPrice := 0.0;
ClientDataSet1.First;
while not ClientDataSet1.Eof do
begin
GTotal := GTotal + ClientDataSet1.FieldByName(‘Quantity’).AsInteger;
GTotalPrice := GTotalPrice +
( ClientDataSet1.FieldByName(‘UnitPrice’).AsFloat * ClientDataSet1.FieldByName(‘Quantity’).AsInteger );
ClientDataSet1.Next;
end;
finally
ClientDataSet1.GotoBookmark(B);
ClientDataSet1.FreeBookmark(B);
ClientDataSet1.EnableControls;
end;
end;
And in the OnColumnSummaryResult of the grid do the following
procedure TMainForm.UniDBGrid1ColumnSummaryResult(Column: TUniDBGridColumn;
GroupFieldValue: Variant; Attribs: TUniCellAttribs; var Result: string);
begin
if SameText(Column.FieldName, ‘quantity’) then
begin
Result:=Format(‘Total Units: %d’, [GTotal]);
Attribs.Font.Style:=[fsBold];
Attribs.Font.Color:=clGreen;
end
else if SameText(Column.FieldName, ‘unitprice’) then
begin
Result:=’Total Cost: ‘+FormatCurr(‘0,0.00 ‘, GTotalPrice) + FmtSettings.CurrencyString;
Attribs.Font.Style:=[fsBold];
Attribs.Font.Color:=clNavy;
end;
end;
Where GTotal is declared as a field. It is basically clear, we calculate the results, throw them into the fields, and in the output of the results we take the information from the fields.