Add a Dimension to the Column Axis of the PivotGrid
Environment
Product | Progress® Kendo UI® PivotGrid for jQuery |
Operating System | Windows 10 64bit |
Browser | Google Chrome |
Browser Version | 61.0.3163.100 |
Description
How can I add a new dimension to the column axis of the Kendo UI PivotGrid?
Solution
The following example demonstrates how to use the Kendo UI PivotGrid API to add a new dimension to the column axis of the widget.
<script src="https://demos.telerik.com/kendo-ui/content/shared/js/products.js"></script>
<div id="example">
<button id="add">Add "ProductName"</button>
<div id="pivotgrid"></div>
<script>
$(document).ready(function () {
var pivotgrid = $("#pivotgrid").kendoPivotGrid({
columnWidth: 120,
height: 570,
dataSource: {
data: products,
schema: {
model: {
fields: {
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsInStock: { type: "number" },
Discontinued: { type: "boolean" },
CategoryName: { field: "Category.CategoryName" }
}
},
cube: {
dimensions: {
ProductName: { caption: "All Products" },
CategoryName: { caption: "All Categories" },
Discontinued: { caption: "Discontinued" }
},
measures: {
"Sum": { field: "UnitPrice", format: "{0:c}", aggregate: "sum" }
}
}
},
columns: [{ name: "CategoryName", expand: true }],
rows: [{ name: "Discontinued", expand: true }],
measures: ["Sum"]
}
}).data("kendoPivotGrid");
$("#add").click(function() {
var ds = pivotgrid.dataSource;
var columns = ds.columns();
columns.push("ProductName");
ds.columns(columns);
});
});
</script>
</div>