Data filtering

Top  Previous  Next

Dialogs can be used to filter the data which is printed in a report. For example, you have a report, which prints a list of all the employees. By using a dialog, you can choose one or several from it, and then when building the report, the data is filtered so that only the chosen employees can be shown.

 

For using the data filtering, it is necessary that the initial report contains all the data. The name "filtering" itself, assumes that, unnecessary data will not be printed when building the report.

 

The simplest method for organizing data filtering is to use the Filter property on the "Data" band. In the band editor, you can indicate the filter expression, for example:

 

dataBandFilter

 

By using the dialogue, you can ask a value from a user, and use it in the filtering expression. Look at the "Simple filter" example in the "Examples" section.

 

This method can be used, if a simple value is needed. If the task is to display a list of values and inquire one or several from it, implementing this becomes difficult. You may think that, it is a simple task - showing a list of employees in the ListBoxControl control element and choosing one or several values. For implementing this, you need to use the script, which does the following:

 

get the data source by its name;
initialize data;
fill the ListBoxControl with the data from data source;
after choosing the employee, build a filter expression that will be used in the "Data" band.

 

FastReport can do this automatically. For this, automatic filtering is used, which we will observe now.