Calculate Sum after Filtering in FNCDataGrid

i tried to use the OnAfterApplyFilter at the FNCDataGridDatabaseAdapter to Calculate the sum of one Column and show it in the Sum-Row.
But this event is not triggered when i choose a searchitem in the Filter in one Column of the FNCDataGrid. The Rows are filtered but the Sum is allways the sum of all Values in the Dataset.

I have Set the Calculation in the FormCreate:

  // Summe unter RechBetrag schreiben
  GrdKosten.RowCount:=GrdKosten.RowCount+1;
  GrdKosten.FixedBottomRowCount:=1;
  GrdKosten.ColumnCalculations[5,'Summe: '] :=
  [
   CreateNormalColumnCalculation(gcmSum)
  ];

When i filter any column i want to see the sum of this filtered Rows in the SumField of the RechBetrag Column(5).
Also i dont see the Text 'Summe:' in the Sumary Row.

In LoadMode = almAllRecords, you need to use the OnAfterApplyFilter of the grid, because the filter is applied directly on the data instead of the dataset.

i used this event to calculate:

procedure TfrmKosten.grdKostenAfterApplyFilter(Sender: TObject; AColumn: Integer; ACondition: string);
begin
// Wird getriggert nachdem, im Grid, eine Filteraktion ausgeführt wird
// Wird hier verwendet um die Summe
  grdKosten.UpdateCalculations;
end;

in FormCreate is:


  GridDatabaseAdapterKo.DataSource := DM.dsKosten;
  GridDatabaseAdapterKo.LoadMode := almAllRecords;

But it show the sum of all rows in the dataset not the Records shown in the grid.

There is an option to exclude hidden rows:

TMSFNCDataGrid1.Options.Calculations.IncludeHiddenRows := False;

this is the solution to the problem.

Thank you Pieter

1 Like