Skip to main content

Providing Data

  • 2 minutes to read

The Web Dashboard allows you to bind dashboard items to data in a uniform and similar manner. See the Bind Dashboard Items to Data in the Web Dashboard’s UI topic for common information.

The difference is in the data sections that the specific dashboard item has. This topic describes how to bind the Grid dashboard item to data.

Binding to Data in the Web Dashboard

The image below shows a sample Grid dashboard item that is bound to data.

wdd-grid-binding

To bind the Grid dashboard item to data, click a placeholder contained in one of the available data sections and select the required data source field in the Binding section of the invoked data item menu.

The table below lists and describes the Grid’s data sections.

Section API Processed as Description
Columns GridItem.columns Dimension or Measure (depending on the selected column type) Contains data items that provide values for grid columns. The data item menu allows you to select the column type and specify their options.
Sparkline GridItem.sparklineArgument Dimension Contains a data item that provides arguments for sparkline columns. To learn more, see Columns.

Example

The following example shows how to create the Grid dashboard item, bind it to data and add to the existing dashboard.

Create data items (measures and dimensions) and use the DataItem.dataMember property to bind them to the existing data source’s columns. Then use the created measures and dimensions in the dashboard item to bind it to data.

After you add the created dashboard item to the Dashboard.items collection, call the Dashboard.rebuildLayout method to rebuild the dashboard layout and display changes.

// Use the line below for a modular approach:
// import * as Model from 'devexpress-dashboard/model'
// Use the line below for an approach with global namespaces:
// var Model = DevExpress.Dashboard.Model;

// ...
public createGridItem() { 
    // Create data items for the Grid dashboard item.
    var gridCategoryName = new Model.Dimension();
    gridCategoryName.dataMember("CategoryName");
    var gridProductName = new Model.Dimension();
    gridProductName.dataMember("ProductName");
    var gridUnitPrice = new Model.Measure();
    gridUnitPrice.dataMember("UnitPrice");    

    // Create the Grid dashboard item and bind it to data.
    var gridItem = new Model.GridItem();
    gridItem.name('grid');
    gridItem.dataSource(sqlDataSource.componentName());
    gridItem.dataMember(sqlDataSource.queries()[0].name());

    var gridColumn1 = new Model.GridDimensionColumn(gridItem);
    gridColumn1.dimension(gridProductName);
    gridItem.columns.push(gridColumn1);

    var gridColumn2 = new Model.GridMeasureColumn(gridItem);
    gridColumn2.measure(gridUnitPrice);
    gridItem.columns.push(gridColumn2);

    var gridColumn3 = new Model.GridHyperlinkColumn(gridItem);
    gridColumn3.displayValue(gridCategoryName);
    gridColumn3.uriPattern("http://en.wikipedia.org/wiki/{0}");
    gridItem.columns.push(gridColumn3);

    control.dashboard().items.push(gridItem);
    // ...
    control.dashboard().rebuildLayout();
}