Skip to main content

Adding Ad Hoc Filters to the .NET Engine


New in version 11.0.

Our engine API supports filters in the select. It moves the filtering logic from the template to the API creating a specific select for each query.

What this Does

This allows you to change what data is displayed in the generated report. You can create one template and then, based on the value of variables passed to the data source when running the report, set what rows of data are rendered in the report.

For example, you may have a table listing all sales for your company. You can then pass in filters to limit the table to sales in the western region, over the previous quarter. The next run may be all sales for one sale rep. You can filter any way you wish without ever changing the template.

The Code

Download This is also installed as a sample program in the .net engine samples directory.

Here’s the additional code to select several specific rows of data:

KeyPairDictionary adHocVariables = new KeyPairDictionary();
  adHocVariables.Add(“employeeId”, new FilterList(FilterBase.SORT.NO_OVERRIDE, “employeeId”, new object[] { 1, 2 }));
datasource.Map = adHocVariables;
report.ProcessData(datasource, “”);
And here is the code for a condition:
KeyPairDictionary adHocVariables = new KeyPairDictionary();
new FilterCondition(FilterBase.SORT.NO_OVERRIDE, “employeeBirthDate”,
new FilterCondition.Condition[] { new FilterCondition.Condition(“BirthDate”, FilterCondition.Condition.OPERATION.GREATER_THAN_OR_EQUAL, new DateTime(1948, 12, 8)),
new FilterCondition.Condition(“BirthDate”, FilterCondition.Condition.OPERATION.LESS_THAN, new DateTime(1958, 1, 9)) }, true));
datasource.Map = adHocVariables;
report.ProcessData(datasource, “”);

It makes it incredibly easy to use this new functionality. And I think this will become very popular (essential for many). Because it moves the filtering logic from the template, and removes it from creating a specific select for each query, and instead leaves it that you just define the filter and we take care of the rest.

  • Was this article helpful?