Header control in grouped reports

Header control in grouped reports

In some reports or screen form print formats, you need to create multiple independent reports using one print layout. For example, in the stock-in report, you must display a separate report for each store; in the list of stock-out records, you need to create separate invoices for each of the selected documents. In order to do so, you need to use grouped print layouts with a logical page numbering system. In the page header of this print layout, you need to display only those filter values that belong to the current group, not all values.

The filter values according to which the grouping is carried out can be returned both in the main data sets of the report and in a custom data set. The first situation is relevant for screen form print layouts, the second, for reports.

The filter values can be received from the main menu; however, to create a grouped print layout, it suffices to:

  • in the FilterNDataSet attribute, specify the name of the data set,

  • in the FilterNFieldName attribute, specify the name of the field from which the filter values will be received.

  • set FilterNFromCurrentRecord to True,

  • specify the filter header value for the FilterNCaption attribute if necessary.

When you use a special data set with filter values, perform the following on the Code tab:

  • Create both a global variable, e.g. FilterString, plus the OnBeforePrint event handler for the TssPageHeader component.

    In the event handler, you need to create a filter for custom data sets by the main data set group and allow for a TssPageHeader component data reboot.

var FilterString: String =''; 
procedure TssPageHeader2OnBeforePrint(Sender: TfrxComponent); 
begin 
  if TssFastReportDataSet(MasterData1.DataSet).DisplayText('stor_ID') <> FilterStore 
  then begin FilterStore := TssFastReportDataSet(MasterData1.DataSet).DisplayText('stor_ID'); 
// Filter stores TssFastReportDataSet(Report.GetDataSet('Stores')) := 'SELECT FROM Main WHERE stor_ID='+FilterStore; 
// Filter companies TssFastReportDataSet(Report.GetDataSet('OwnFirms')) := 'SELECT FROM Main WHERE stor_ID='+FilterStore; 
// Update data in the page header component TssPageHeader2.ReloadData; 
  end; 
end;