The value is always zero.
My grid code and related scripts are as below,
<ej-grid id="FlatGrid" show-summary="true" template-refresh="templateRefresh" cell-save="onCellSave">
<e-datamanager url="/Adjustments/LineDataSource?documentId=@Model.Id" batch-url="/Adjustments/LineBatchUpdate" adaptor="UrlAdaptor" />
<e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" show-confirm-dialog="false" row-position="@(RowPosition.Bottom)" edit-mode="Batch"></e-edit-settings>
<e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() {"add","delete" })"></e-toolbar-settings>
<e-columns>
<e-column field="Id" visible="false"></e-column>
<e-column field="SKU" header-text="SKU" width="80">
<e-edit-template create="create" read="read" write="write">
</e-edit-template>
</e-column>
<e-column field="Volume" header-text="Volume" edit-type="@(EditingType.Numeric)" format="{0:N3}" numeric-edit-options="@new EditorProperties() { DecimalPlaces = 3,ShowSpinButton=false}" width="10"></e-column>
<e-column field="UnitPrice" header-text="Price" edit-type="@(EditingType.Numeric)" format="{0:C2}" numeric-edit-options="@new EditorProperties() { DecimalPlaces = 2,ShowSpinButton=false}" width="10"></e-column>
<e-column field="TotalPrice" header-text="Total Price" format="{0:C2}" template="{{:Volume * UnitPrice }}" allow-editing="false" text-align="Right" width="15"></e-column>
<e-column header-Text="" width="12">
<e-column-commands>
<e-column-command type="delete">
<e-button-options size="Normal" show-rounded-corner="true" content-type="@ContentType.ImageOnly" prefix-icon="e-icon e-cancel"></e-button-options>
</e-column-command>
</e-column-commands>
</e-column>
</e-columns>
<e-summary-rows>
<e-summary-row title="Summary">
<e-summary-columns>
<e-summary-column summary-type="Sum" display-column="Volume" datamember="Volume" format="{0:N3}" />
<e-summary-column summary-type="Custom" display-column="TotalPrice" format="{0:C2}" custom-summary-value="totalprice" />
</e-summary-columns>
</e-summary-row>
</e-summary-rows>
</ej-grid>
function onCellSave(args) {
if (args.columnName == "Volume" || args.columnName == "UnitPrice") {
var formatter = new Intl.NumberFormat('en-NZ', {
style: 'currency',
currency: 'NZD',
minimumFractionDigits: 2,
});
if (args.columnName == "Volume")
$(args.cell.closest("tr")).find(".e-templatecell").text(formatter.format(args.value * args.rowData.UnitPrice));
else $(args.cell.closest("tr")).find(".e-templatecell").text(formatter.format(args.value * args.rowData.Volume));
}
}
function totalprice() {
var volval, unitval;
var totalval, sumval = [];
var gridObj = $("#FlatGrid").ejGrid("instance");
sumval = [];
var data = gridObj.model.dataSource;
for (i = 0; i < data.length; i++) {
volval = data[i].Volume;
unitval = data[i].UnitPrice;
totalval = volval * unitval;
sumval.push(totalval);
}
var result = ej.sum(sumval);
return (result);
}
Clientside:-
<ej-grid id="FlatGrid" allow-paging="true" show-summary="true">
<e-datamanager url="/Home/DataSource" insert-url="/Home/CellEditInsert" update-url="/Home/CellEditUpdate" remove-url="/Home/CellEditDelete" adaptor="UrlAdaptor"></e-datamanager>
<e-summary-rows>
<e-summary-row title="Currency">
<e-summary-columns>
<e-summary-column summary-type="Custom" custom-summary-value="currency" format="{0:C2}" display-column="Freight" />
</e-summary-columns>
</e-summary-row>
</e-summary-rows>
<e-columns>
<e-column field="OrderID" header-text="Order ID" width="80" text-align="Right"></e-column>
<e-column field="EmployeeID" header-text="Employee ID" text-align="Right" width="80"></e-column>
</e-columns>
</ej-grid>
Serverside:-
public partial class GridController : Controller
{
public ActionResult GridFeatures()
{
ViewBag.dataSource = OrderRepository.GetAllRecords().ToList();
return View();
}
public ActionResult DataSource([FromBody]DataManager dm)
{
IEnumerable DataSource = OrderRepository.GetAllRecords();
DataOperations ds = new DataOperations();
List<string> str = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
str.Add(dm.Aggregates[i].Field);
result.aggregate = ds.PerformSelect(DataSource, str);
}
DataSource = ds.PerformSkip(DataSource, dm.Skip);
result.result = ds.PerformTake(DataSource, dm.Take);
result.count = DataSource.AsQueryable().Count();
return Json(result, JsonRequestBehavior.AllowGet);
}
public class DataResult
{
public IEnumerable result { get; set; }
public int count { get; set; }
public IEnumerable aggregate { get; set; }
public IEnumerable groupDs { get; set; }
}
}
|