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.

Save and Restore Grouping State in a Data Grid

Hide navigation
RSS
Modified on Fri, 16 May 2014 11:04 AM Categorized as Data Grid, Script Library
Dundas Dashboard Script LibraryPrevious


Overview

This example shows how to use scripting to save and restore the grouping state in a data grid (e.g. when the interactive Group Panel is enabled). You can use this example as a basis for ensuring that dashboard users don't lose their grouping choices as they navigate between dashboards.

Tip: This article also shows how to use the Globals property of the script services object to store and recall your own global variable values.

Setup

Dataset

For this example, use the Support by Employee by Month dataset that is included with the Sonatica Performance samples (which you can install via the Deployment Center). Or, use any other dataset of your choice.

The Support by Employee by Month dataset in the toolbox.

The Support by Employee by Month
dataset in the toolbox.


Dashboard

Create the initial dashboard as follows:

  1. Drag the Support by Employee by Month dataset from the toolbox to the dashboard canvas.
  2. In the Data Settings Configuration and Data Grid Binding Setup wizard, accept the default options for each step.
  3. Go to the Properties window for the data grid and locate the View property. Click its ellipsis button.
  4. In the View property dialog, enable interactive grouping as follows:
    • Set the Group Panel Visibility property to Visible.
    • Set the Enable Column Grouping property to True.
  5. Add a Button control to the dashboard and set its Text property to Save.
  6. Add another Button control to the dashboard and set its Text property to Load.
  7. Save, then preview the dashboard. Verify that you can use the data grid's Group Panel to apply grouping interactively.

Script

Button1.Click

Next, add the following script code for the Click interaction of the Save button. The script saves the group description's column ids into a global variable.

List gds = new List(); List< string > groupid = new List< string >(); foreach (DashboardDataGridGroupDescription gd in DataGrid1.GroupDescriptions) { groupid.Add(gd.DataColumnId); } services.Globals.Remove("groups"); services.Globals.Add("groups", groupid);



Button2.Click

Add the following script code for the Click interaction of the Load button. The script loads group descriptions from a global variable into the data grid. You can also place this script on the Dashboard's Load Interaction if you need to restore the group descriptions on load of the dashboard.

DashboardDataGrid grid = DataGrid1; DataResult dr = grid.DataDescriptors[0].DataResult;

grid.GroupDescriptions.Clear(); if (services.Globals.ContainsKey("groups")) { DataGrid1.GroupDescriptions.Clear(); List< string > gds = services.Globals["groups"]; List id = new List(); foreach (object gd in gds) { DashboardDataGridGroupDescription gdx = new DashboardDataGridGroupDescription(); gdx.DataColumnId = new Guid(gd); gdx.Text = grid.GetColumnByDataColumnId(new Guid(gd)).HeaderText; grid.GroupDescriptions.Add(gdx) } }


Testing

To test the example:

  1. View the dashboard and drag a column header to the interactive Group Panel.
  2. Click the Save button.
  3. Clear the interactive Group Panel.
  4. Click the Load button and observe the previously saved group is restored.

Tip: The data grid's Group Description Collection Changed interaction lets you know whenever the group description collection for a data grid has changed.

Related topics


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

Copyright © 2009-2014 Dundas Data Visualization, Inc.