Hi,
Below is my grid code:
@Html.EJS().Grid("products").DataSource((IEnumerable<object>)ViewBag.products).EnableStickyHeader(true).Width("auto").Columns(col =>
{
col.Field("ProductCode").HeaderText("Code").HeaderText("Code").IsPrimaryKey(true).AutoFit(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.Field("Description").HeaderText("Item").Width("400px").HeaderText("Item").AllowEditing(false).Add();
col.Field("Colour").HeaderText("Colour").AllowEditing(false).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.Field("Price").HeaderText("Price Ex VAT").Format("C2").Width("150px").AllowEditing(false).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.Field("Pack").HeaderText("Pack").AllowEditing(false).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.Field("Barcode").HeaderText("Barcode").AllowEditing(false).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.HeaderText("Image").Template("#template").AllowEditing(false).Width("90px").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.Field("QtyToOrder").HeaderText("Order").EditType("numericedit").ValidationRules(new { required = true }).Edit(new { @params= new Syncfusion.EJ2.Inputs.NumericTextBox() { ShowSpinButton = false, Min = 0, ValidateDecimalOnType=true,Decimals=0,Format="N" }}).Width("100px").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
col.Field("LineTotal").HeaderText("Total").AllowEditing(false).Format("C2").Width("150px").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
}).CellSave("calcTotal").Locale("en-ZA").GridLines(Syncfusion.EJ2.Grids.GridLine.Both).EnableAltRow(true).Load("load").Height("400px").EditSettings(edit => { edit.AllowEditing(true).AllowAdding(false).AllowDeleting(false).Mode(Syncfusion.EJ2.Grids.EditMode.Batch).ShowConfirmDialog(false); }).Toolbar(new List<string>() { "Search" }).ActionBegin("actionBegin").ActionComplete("actionComplete").Aggregates(agg =>
{ agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "LineTotal", Format = "C2", Type = "Sum", FooterTemplate = "Excl Total: ${Sum}" } }).Add();
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "LineTotal", Format = "C2", Type = "Custom", FooterTemplate = "VAT: ${Custom}", CustomAggregate = "vatFn" } }).Add();
//agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "LineTotal", Format = "C2", Type = "Custom", FooterTemplate = "Total: ${Custom}", CustomAggregate = "totalFn" } }).Add();
}).BeforeBatchSave("btchSave").DataBound("calcAggs").Render()
As you can see, I currently have an aggregate on the Line Total column that sums up the line totals. As the grid is in batch editing mode, this aggregate sums every time one of the rows are edited. Now I need to add to more aggregates that will need to do some math based on the first aggregate column.
The first one of the custom aggregates, needs to take the sum of the Line Total values and multiply it by 0.15
The second custom aggregate needs to take the sum of the line totals and add it to the second custom aggregate value and then be displayed.
The aggregate values must all be responsive as with the first sum aggregate.
Is this possible
|
@Html.EJS().Grid("products").DataSource((IEnumerable<object>)ViewBag.DataSource).EnableStickyHeader(true).Width("auto").Columns(col =>
{
---
col.Field("Freight").HeaderText("Total").AllowEditing(true).Format("C2").Width("150px").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add();
}).Aggregates(agg =>
{
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Sum", FooterTemplate = "Excl Total: ${Sum}" } }).Add();
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Custom", FooterTemplate = "VAT: ${Custom}", CustomAggregate = "vatFn" } }).Add();
agg.Columns(new List<Syncfusion.EJ2.Grids.GridAggregateColumn>() { new Syncfusion.EJ2.Grids.GridAggregateColumn() { Field = "Freight", Format = "C2", Type = "Custom", FooterTemplate = "Total: ${Custom}", CustomAggregate = "totalFn" } }).Add();
}).BeforeBatchSave("btchSave").DataBound("calcAggs").Render()
<script>
function vatFn(data, aggColumn) {
if (data.aggregates && data.aggregates['Freight - sum']) {
return data.aggregates['Freight - sum'] * 1.5; // get the Freight column aggregate sum
} else {
return null;
}
};
function totalFn (data, aggColumn) {
if (data.aggregates && data.aggregates['Freight - sum']) {
return (
data.aggregates['Freight - sum'] + data.aggregates['Freight - sum'] * 1.5 // get the Freight column aggregate sum
);
} else {
return null;
}
};
</script>
|
Thank you. This works perfectly.
Now, is there a way to customize the aggregate CSS? The values become quite large and the display suffers a bit:
That's exactly what I need. The innerText must be in single line and not wrap to next line.
|
col.Field("LineTotal").HeaderText("Total").AllowEditing(false).Format("C2").Width("220px").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Add(); |
I can't believe I missed that. It works perfectly. Thank you