Articles in this section
Category / Section

How to handle server-side filtering with parameters in a dashboard?

Published:

Server-Side Filtering in JavaScript Embedding

Server-side filtering lets you ensure secured access for users to their data in the embedded dashboard. In the Bold BI embedded application, you can pass the filter parameters to the authorization endpoint dynamically using the query parameter embed_datasource_filter. Following are some scenarios in which filtering can be applied using this query parameter.

  1. Filtering with URL Parameter only.
  2. Filtering with Dashboard Parameter only.
  3. Filtering with both URL Parameter and Dashboard Parameter.
  4. Filtering with URL Parameter from different data sources.

Filtering with URL Parameter Only

To filter with a URL parameter only, follow these steps:

  1. Identify the column name you wish to filter from the data source edit page. For example, if you want to filter by the ProductName column for the value ‘Alice Mutton’, you would find this on the edit page.

    image.png

    In the above image, the ProductName is the column whose values need to be filtered by Alice Mutton.

  2. In the embedded application, perform filtering with the embed_datasource_filter query parameter in the authorization endpoint. This can be done as shown in the following code snippet:


public string GetDetails([FromBody] object embedQuerString) {
​   var embedClass = Newtonsoft.Json.JsonConvert.DeserializeObject<EmbedClass>(embedQuerString.ToString()); 
   var embedQuery = embedClass.embedQuerString;            // User your user-email as embed_user_email  
   embedQuery += "&embed_user_email=" + EmbedProperties.UserEmail;
   double timeStamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
   embedQuery += "&embed_server_timestamp=" + timeStamp;
   embedQuery += "&embed_datasource_filter="+ "[{&ProductName=Alice Mutton}]";            
   var embedDetailsUrl = "/embed/authorize?" + embedQuery + "&embed_signature=" + GetSignatureUrl(embedQuery);            
   using (var client = new HttpClient())            
   {                
   client.BaseAddress = new Uri(embedClass.dashboardServerApiUrl);                
   client.DefaultRequestHeaders.Accept.Clear();                
   var result = client.GetAsync(embedClass.dashboardServerApiUrl + embedDetailsUrl).Result;                
   string resultContent = result.Content.ReadAsStringAsync().Result;                
   return resultContent;            
   }       
   }

Filtering with Dashboard Parameter Only

To filter with a dashboard parameter only, follow these steps:

  1. Create a dashboard parameter. For example, a parameter could be created with CountryName and the value ‘USA’.

    image.png

  2. Assign the parameter to the column named Country in the code view window and save the data source.

    image.png

  3. Pass the dashboard parameter along with its value to the query parameter embed_datasource_filter as shown in the following code snippet:

embedQuery += "&embed_datasource_filter="+"[{&&CountryName=Switzerland}]";

Filtering with Both URL Parameter and Dashboard Parameter

Filtering can be applied by passing both URL parameters and Dashboard parameters to the embed_datasource_filter query parameter. More than one parameters are separated by ‘&&’. Here is a code sample:

embedQuery += "&embed_datasource_filter="+ "[{&ProductName=Alice Mutton&&CountryName=Switzerland}]";

Filtering with Columns from Two Different Data Sources

If a dashboard is configured with more than one data sources and you need to filter by a column that exists in multiple data sources, add the name of the data source as prefix to the column name and separated by dot ‘.’.

image.png

For example, in the dashboard shown above, the widget Total Metals by Country is configured with the data source Olympics 2012 Dashboard_OlympicsDS new, and the widget Medal details by Country is configured with the data source Olympics 2012 Dashboard_MedalsPerCapital.

In the embedded application, add the query parameter embed_datasource_filter in the authorization endpoint with the filtering parameter as follows.

embedQuery += "&embed_datasource_filter=" + "[{Olympics 2012 Dashboard_MedalsPerCapital.Country=China}]";

In this case, the filter is applied only to those widgets associated with the data source referred to in the filter parameter.

image.png

On running the application, you can find the filter is applied only to those widgets associated with the data source referred to in the filter parameter, as shown in the above image.

Similarly, when you apply the filter by column of the other data source instead, as shown in the below code snippet, the filter gets applied just to the map widget to which the corresponding data source is connected.

embedQuery += "&embed_datasource_filter=" + "[{Olympics 2012 Dashboard_OlympicsDS new.Country=China}]"

image.png

References

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
SM
Written by Soundarya Mani Meharan
Updated:
Comments (0)
Please  to leave a comment
Access denied
Access denied