416.467.9100 | Dundas Data Visualization | Login
Welcome Guest
This is the support page for the legacy Dundas Dashboard application. For assistance with the current Dundas BI application please click here.
Dashboard v5.0

This site makes extensive use of JavaScript.

Please enable JavaScript in your web browser and reload the page before proceeding.

Dynamic filtering with multi-selection

Hide navigation
RSS
Modified on Wed, 25 Jun 2014 02:41 PM Categorized as Data Grid, Legend, Level-Expert, Parameter Controls, Parameters, Script Library, Scripting

Overview

This article will show how to achieve dynamic filtering with multi-selection. The setup involves populating a legend control based on user selection and use that to further filter the associated control..

In the example used in this article, viewers will see one dropdown, one legend control for multi-selection and a data grid. The data grid is used to store various countries along with the continents they belong to. Selecting a continent filters the datagrid with all the countries belonging to the continent as well as populates the "Country" legend control with the results. Selecting a country or multiple countries further filters the datagrid.

To achieve this goal, a second hidden DataGrid and hidden checkboxlist parameter are used. The idea behind using a second datagrid is to store the values that will populate the legend. This will ensure that when the filter is applied, there is no interference between populating the legend and filtering the control.

Controls used

DataGrid1: Original data grid that needs to be filtered.

DataGrid2: DataGrid to store the values and populate the dropdown. This will be placed outside the canvas. In this example, DataGrid1 and DataGrid2 are the same.

Legend1 (Country): This legend gets populated by selection in Continent parameter and the selected value filters DataGrid1.

Dropdown Parameter (Continent): Parameter acting on both the data grids. Configure the parameter to filter on “Continent” column. The selection in this dropdown is used to populate the Country dropdown.

Parameter (CountryParam): Parameter acting on DataGrid1 that allows multi-selection. Configure the parameter to filter on the “Country” column. The value from Legend1 gets passed to this parameter. This will be placed outside the canvas.

Interactions Used

Load Interaction of the Dashboard

Parameter Changed Interaction of the Dashboard

Item Check Changed Interaction of Legend control

Steps

KPI/Dataset

The KPI/Dataset is setup as shown below:

Image

Filters are setup on Continent and Country columns:

Continent: Single value selection
Image

Country: Multi value selection
Image



Add parameters

Add the Continent and CountryParam parameters. Place the DataGrid1 on the canvas before adding these:

Image

Place the controls

DataGrid1, Legend1, Continent parameter should be on the dashboard canvas. Place DataGrid2 and CountryParam outside the canvas.

Image

Load Interaction

Add the load interaction below that initializes a global variable that will be used to check which condition to fore in the legend’s Item Check Changed interaction:



//This flag will determine which if condition gets executed //in the Item Check Changed Interaction "Select Items" of the legend control

//The flag is initialized to 0 on load in this step as a globlal variable

if (services.Globals.ContainsKey("Selection_Flag")) // Check if the key is present { services.Globals.Remove("Selection_Flag"); }

services.Globals.Add("Selection_Flag",0); //Store the value into the global variable.


Parameter Changed Interaction

Place the script below in the parameter changed interaction that will load the values into the legend on every change of the Continent parameter.

  1. UNSUPPORTED UNLIMITED

//Check if the Continent parameter has changed if(e.Parameter.Name == "Continent") { //Assign the flag to 0 services.Globals"Selection_Flag" = 0; //Loop through our DataGrid and add each country to the Country Legend object DataGrid = DataGrid2; object Legend = Country; //Index of the country column on the KPI/Dataset int itemIndex = 1; //Clear the Legend items try { Legend.CustomLegendItems.Clear(); }

catch {} //Add the first item to select all values. DashboardLegendItem i = new DashboardLegendItem(); i.Text = "Select All"; Legend.CustomLegendItems.Add(i);

//Add all the visible items from DataGrid2 foreach (object o in DataGrid.DataDescriptors0.DataResult.DataPoints) { string state = (String)o.FieldValuesitemIndex; DashboardLegendItem i = new DashboardLegendItem(); i.Text = state; Legend.CustomLegendItems.Add(i); Legend.IsItemCheckBoxVisible = true; }

//Set the MarkerFill and the deselect the checkboxes of all the legend items foreach(DashboardLegendItem legend_item in Legend.CustomLegendItems) { legend_item.MarkerFill = new DashboardSolidColorBrush(Colors.Transparent); legend_item.IsCheckBoxChecked = false; } //Set the Country parameter to select all values loaded in the legend CountryParam.FilterValues0.NamedTokenValue = NamedToken.All; CountryParam.InvalidateFilter(); }


Item Check Changed Interaction

Place the following code in the Item Check Changed Interaction that passes the selected value to the CountryParam parameter and filters the DataGrid1 further. The global variable Selection_Flag is used to check if an item is checked or unchecked:



  1. UNSUPPORTED UNLIMITED

if(e.IsChecked) { #TRACE "Checked"; //Check if "Select All" is selected if(sender.CustomLegendItems0.IsCheckBoxChecked) { //Select all values using NamedToken.All CountryParam.FilterValues0.NamedTokenValue = NamedToken.All; CountryParam.InvalidateFilter(); //Check all the items in the legend foreach(DashboardLegendItem legend_item in sender.CustomLegendItems) { legend_item.IsCheckBoxChecked = true; } } //If other values are selected else { sender.CustomLegendItems0.IsCheckBoxChecked = false;

//Store all the selected values in a list List list = new List(); list.Clear(); foreach(DashboardLegendItem legend_item in sender.CustomLegendItems) { if(legend_item.IsCheckBoxChecked) { list.Add(legend_item.Text); } } //Load the values from the list to the CountryParam parameter CountryParam.FilterValues.Clear();

for (int j=0;jj); DashboardFilterValueData fvd = new DashboardFilterValueData(); fvd.MemberValues.Add(mvd); CountryParam.FilterValues.Add(fvd); } CountryParam.InvalidateFilter(); }

services.Globals"Selection_Flag" = 1;

}

else if(!e.IsChecked && services.Globals"Selection_Flag"!= 0 ) { #TRACE "Unchecked"; //Check if "Select All" is selected if(sender.CustomLegendItems0.IsCheckBoxChecked) { CountryParam.FilterValues0.NamedTokenValue = NamedToken.All; CountryParam.InvalidateFilter(); } //If other values are selected else { sender.CustomLegendItems0.IsCheckBoxChecked = false; //Store all the selected values in a list List list = new List(); list.Clear(); foreach(DashboardLegendItem legend_item in sender.CustomLegendItems) { if(legend_item.IsCheckBoxChecked) { list.Add(legend_item.Text); } } //Load the values from the list to the CountryParam parameter CountryParam.FilterValues.Clear();

for (int j=0;jj); DashboardFilterValueData fvd = new DashboardFilterValueData(); fvd.MemberValues.Add(mvd); CountryParam.FilterValues.Add(fvd); } CountryParam.InvalidateFilter(); }

}




Result

On Load

Image

Parameter change (Continent selection)

Image



Item check change (Country selection)

Image


Item check change (Select all)

Image

Related Topics

About Dundas | Contact Us Follow us on Twitter! | Privacy Statement | Report Site Issues

Copyright © 2009-2014 Dundas Data Visualization, Inc.