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 Pivot dashboard item to data.
Binding to Data in the Web Dashboard
The image below shows a sample Pivot dashboard item that is bound to data.
To bind the Pivot 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 Pivot’s data sections.
Section | API | Processed as | Description |
---|---|---|---|
Values | PivotItem.values | Measure | Contains data items used to calculate values displayed in the pivot table. |
Columns | PivotItem.columns | Dimension | Contains data items whose values are used to label columns. |
Rows | PivotItem.rows | Dimension | Contains data items whose values are used to label rows. |
The following example shows how to create the Pivot 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 createPivotItem() {
// Create data items for the Pivot dashboard item.
var pivotCategoryName = new Model.Dimension();
pivotCategoryName.dataMember("CategoryName");
var pivotProductName = new Model.Dimension();
pivotProductName.dataMember("ProductName");
var pivotCountry = new Model.Dimension();
pivotCountry.dataMember("Country");
var pivotFullName = new Model.Dimension();
pivotFullName.dataMember("FullName");
var pivotExtendedPrice = new Model.Measure();
pivotExtendedPrice.dataMember("ExtendedPrice");
// Create the Pivot dashboard item and bind it to data.
var pivotItem = new Model.PivotItem();
pivotItem.name('pivot');
pivotItem.dataSource(sqlDataSource.componentName());
pivotItem.dataMember(sqlDataSource.queries()[0].name());
pivotItem.columns.push(pivotCountry, pivotFullName);
pivotItem.rows.push(pivotCategoryName, pivotProductName);
pivotItem.values.push(pivotExtendedPrice);
control.dashboard().items.push(pivotItem);
// ...
control.dashboard().rebuildLayout();
}