Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
145131 | Jun 7,2019 07:57 PM UTC | Jun 14,2019 10:58 AM UTC | ASP.NET MVC - EJ 2 | 7 |
![]() |
Tags: PivotView |
<script>
document.getElementById("refresh-btn").addEventListener('click', function () {
var pivotGridObj = document.getElementById("PivotGrid").ej2_instances[0];
pivotGridObj.dataSource.values = [{ name: "Sold", caption: "Units Sold"}, { name: "Amount", caption: "Sold Amount" },
{ name: "Total", caption: "Total Price", type: "CalculatedField" }];
});
document.getElementById("reset-btn").addEventListener('click', function () {
var pivotGridObj = document.getElementById("PivotGrid").ej2_instances[0];
pivotGridObj.dataSource.values = [{ name: "Sold", caption: "Units Sold"}, { name: "Amount", caption: "Sold Amount" }];
});
</script> |
<div>
@{var amount = "\"" + "Avg(Amount)" + "\"";}
@Html.EJS().PivotView("PivotGrid").Width("100%").Height("300").DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false).EnableSorting(true)
.CalculatedFieldSettings(calculatedfieldsettings =>
{
calculatedfieldsettings.Name("Total").Formula(amount).Add();
})).AllowCalculatedField(true).ShowFieldList(true).Render()
</div>
<script>
document.getElementById("refresh-btn").addEventListener('click', function () {
var pivotGridObj = document.getElementById("PivotGrid").ej2_instances[0];
pivotGridObj.dataSource.values = [{ name: "Sold", caption: "Units Sold" }, { name: "Amount", caption: "Sold Amount" },
{ name: "Total", caption: "Average of Amount", type: "CalculatedField" }];
});
</script> |
<div>
@{var amount = "\"" + "Avg(Amount)" + "\"";}
@Html.EJS().PivotView("PivotGrid").Width("100%").Height("300").DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false).EnableSorting(true)
.Values(values =>
{
values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Type(Syncfusion.EJ2.PivotView.SummaryTypes.Avg).Add();
}).AllowCalculatedField(true).ShowFieldList(true).Render()
</div>
|
|
Query |
Comments |
1. |
I get all of my 5 Values from a SQL View. Calculations for my purposes are conducted on the SQL side. I don't really have a need for the client-side calculation. In the CalculatedFieldSettings I set the formula like this "calculatedFieldSettings.Name("$/pc").Formula("TotalCostPerPiece").Add();" because I need the "calculation" to just be the value of itself. With that being said, if I don't set the aggregate in the formula (since it's not a traditional client side calculated field), I set the Type in the JS like this: { name: "TotalCostPerPiece", caption: "$/pc", type: "Avg" }. |
You can bind necessary value fields alone in value axis. And, you don’t need to add remaining fields in calculatedFieldSettings. |
2. |
I think the aggregate would default to Sum otherwise. Whether this is supported functionality, or not, it appears to be functioning accurately... |
Yes. By default, values are aggregated as Sum. And, you can change aggregation using Type property. |
@using Syncfusion.EJ2.PivotView
@Html.EJS().PivotView("PivotGrid").Width("100%").Height("300").DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false).EnableSorting(true)
.GridSettings(new PivotViewGridSettings { ColumnWidth = 120, ColumnRender ="columnRender" }).AllowCalculatedField(true).ShowFieldList(true).Render()
<script>
function columnRender(args) {
args.columns[0].width = 100; // You can change each column width here.
}
</script> |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.