This section provides information on the various ways of data filtering to an embedded dashboard.
Filter API | Purpose | End user aware of filter values | |
---|---|---|---|
Server-Side | embed_datasource_filter |
This Query parameter can be used when you intend to filter from the server side of embedding applications in a more secured way. In the Bold BI embedded application, you can pass the filter parameters from the AuthorizeAPI endpoint dynamically using the query parameter `embed_datasource_filter`. | No |
Client-Side | filterParameters |
This API member can be used when you intend to filter from the client side at the initial level rendering of the dashboard itself. | Yes |
By this, you need to pass the filter value in the AuthorizeAPI endpoint. This type of filtering is more secure and can pass n number of filter values.
To pass filters to the embed_datasource_filter
parameter in the AuthorizeAPI endpoint, refer to the following sample in C#(It differs based on your platform language). Here, we have to set both types of filters to the embed_datasource_filter
property in the endpoint.
NOTE: The end user was unable to make changes. We could prevent the user from changing the user ID and filter details.
public string AuthorizeAPI([FromBody] object embedQuerString)
{
var embedClass = Newtonsoft.Json.JsonConvert.DeserializeObject<EmbedClass>(embedQuerString.ToString());
var embedQuery = embedClass.embedQuerString;
// Using common read-only user as useremail
embedQuery += "&embed_user_email=" + “readonlyuser@abc.com”;
double timeStamp = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
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;
}
}
public string GetSignatureUrl(string queryString)
{
if (queryString != null)
{
var encoding = new System.Text.UTF8Encoding();
var keyBytes = encoding.GetBytes(_boldbiIProperties.EmbedSecret);
var messageBytes = encoding.GetBytes(queryString);
using (var hmacsha1 = new HMACSHA256(keyBytes))
{
var hashMessage = hmacsha1.ComputeHash(messageBytes);
return Convert.ToBase64String(hashMessage);
}
}
return string.Empty;
}
NOTE: Filter value should be enclosed with square and curly brackets as mentioned above. For more details, please refer here.
This API member filterParamters
can be used when you intend to filter from the client side at the initial level rendering itself. It can be achieved by using either a URL parameter or a dashboard parameter.
This is an simplest way to apply a filter to the dashboard by using the known column name of the widget.
To use a filter parameter, use the following syntax: Column_Name=value1, value2,…, valueN
Filtering values can be single-valued and multiple-valued. For more details, please refer to the URL Filter.
var dashboard = BoldBI.create({
filterParameters: "ProductName=Alice Mutton",
});
dashboard.loadDashboard();
var dashboard = BoldBI.create({
filterParameters: "ProductName=Alice Mutton,Tofu",
});
dashboard.loadDashboard();
Its a stored procedure of filter value, for this need to configure the dashboard parameter in the datasource level. This can be used when column name is unknown. For more details, Refer to the configuring dashboard parameters.
To use a dashboard parameter, use the following syntax:dashboard_parameter_name=dashboard_parameter_value
where dashboard_parameter_name
represents the saved dashboard parameter in datasource level.
var dashboard = BoldBI.create({
filterParameters: "dashboard_parameter_name=Alice Mutton",
});
dashboard.loadDashboard();
NOTE: Able to pass both parameter in the
filterParameters
API member. For more details, please refer here.
This method can update the filters during on-demand cases after the dashboard has been rendered. Here, you can achieve this by using either the filter parameter, dashboard parameter, or both.
<button onclick="updateFilterValues()">updateFilterValues</button>
updateFilters
method to perform filtering. In the following example, there is a simple demonstration for applying the column name as ProductName and filter Value as Alice Mutton to update the filter value using the updateFilters method. function updateFilterValues()
{
var instance = BoldBI.getInstance("dashboard");
instance.updateFilters("ProductName=Alice Mutton");
}
NOTE: Able to pass both parameter in the
updateFilters
API method. For more details, please refer here.