Filters vs. Parameters in ActiveReports - A JavaScript & .NET Report Tool
ActiveReports.NET is a great reporting tool, not only for simple reports, but for complex, end-user driven reporting as well. With parameters and filters, you, as the developer, can change the data seen by the end-user at runtime. When an end-user opens a viewer from your application, they can filter each field the way that they would like to with parameters. Let’s look into this concept further with an example.
Why Use Report Parameters in a .NET Application?
Let’s say that you created a page report for a customer invoice catalog. You have a thousand customers, and you want to show each customer their invoice. However, without using parameters, each end-user would have to cycle through every single customer’s invoice until they can access their own. With parameters, however, you can create a dropdown menu that requires the end-user to choose the customer ID or customer name that they want to see. When they choose their ID or name, they can only see their invoice, which makes for a smoother experience. You can also create hidden parameters, where the logic is calculated on the back-end without any input from the customer.
So why is there a need for both parameters and filters? Aren’t they the same thing? Although they are similar, the differences are crucial. When setting a parameter, you are letting your users display the records that they want to see. However, if the report parameter is set, but there is no filter associated with it, all the report data will show, just as it would without any parameter. Let’s test this in the desktop designer with this sample report using our NWIND data source that you can grab from our GitHub page.
If you right-click the “Contact Name” node under "Parameters" in the report explorer and select "Edit", you can see how the parameters are set up. If you click the “Available Values” tab and choose “From query”, you can select the dataset to link the parameter to, as well as the “Value” field and “Label” field to link the options to. The label field will show the records of that field within the dropdown, and the value field will link each record with its corresponding value, so most times these options should be the set to the same field.
Connecting Report Filters to Parameters
This is where the filters come into play. To see the change made to your data after selecting a parameter, you need to set a filter that applies the parameter selection to your data. This can be done within a specific control’s properties, or within the entire dataset.
For example, if you select the table from the report explorer and browse around the “Properties” tab, you will see an option called “Filters.” If you click the ellipses within that option, you can add a filter by clicking the green plus sign in the top right corner. You will have to set the “Expression” field to the parameter, so you can either choose <expression…>to open the expression editor and input your parameter under “Parameters”, or enter the parameter manually with an @ sign in front of its name (Ex: =@[ContactName]). After that, set the “Value” field to the field that you want to filter by (Ex: =[ContactName]).
Now, if you preview your report and select an option from the dropdown, your data should display based on the option chosen!
Although parameters need filters to function correctly, filters do not need parameters. If you weren’t using parameters, you could still filter your entire dataset based on whatever field or expression you’d like to create, which would change the report completely, regardless of which end-user was viewing it.
If you had trouble following along through the blog, you can find more detailed information on parameters and filters in ActiveReports 15 Documentation - .NET Report Parameters. Although this guide walked through parameter creation in ActiveReports.NET, it is also possible in ActiveReportsJS; take a look at ARJS Documentation - JavaScript Report Parameters for more help with report parameters.