1. Home
  2. Advanced Topics
  3. Applying Global Filters

Applying Global Filters

Often times you need to apply data restrictions to the report data that your user can see. For example, you need to restrict the currently logged in user to only the Vendors or Distributors they have access to.

Let’s say for example we want to restrict the currently logged in user to only see data for 3 Distributors they have access to. So let’s assume in a database table picked in the report, the Distributor Id column is named “DistributorID”, and current user can only access DistributorID 1, 2 and 3.

So to automatically apply this filter, at initialization in ReportController’s GetSettings method, you can add the following :

    settings.DataFilters = new { DistributorId = "1,2,3" };

and then your sql statement should return WHERE … AND [TableName].[DistributorId] IN (1,2,3)

‘1,2,3’ here is obviously just an example. In a real scenario, you would not hard code the value, but probably pick this value from the claims for the logged in user.  

You can add as many global filters here as you need. So for example, you can add:

      settings.DataFilters = new { DistributorId = "1,2,3", VendorId = "15,16" };

Was this article helpful to you? Yes No

How can we help?