|
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = OrdersDetails.GetAllRecords();
DataOperations operation = 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);
}
IEnumerable aggregate = operation.PerformSelect(DataSource, str);
int count = DataSource.Cast<OrdersDetails>().Count();
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count, aggregate = aggregate }) : Json(DataSource);
} |
|
var customAggregateFn = function(data) {
//we can get the current page records from its args -data
var gridData = grid.dataSource; // get the entire grid datasource by using gridObj.dataSource which returns entire data if the grid having local dataSource
var totalSum = 0;
// do your calculation as you want with the entire dataset
for (var i = 0; i < gridData.length; i++) {
totalSum = totalSum + gridData[i]['Freight'];
}
return totalSum; // return the calculated value
};
var grid = new ej.grids.Grid({
dataSource: window.orderData,
allowPaging: true,
pageSettings: { pageCount: 5 },
columns: [
{ field: 'CustomerName', headerText: 'Customer Name', width: 150 },
{ field: 'Freight', width: 160, format: 'C2', textAlign: 'Right' },
{
field: 'OrderDate',
headerText: 'Order Date',
width: 130,
format: 'yMd',
textAlign: 'Right'
},
{ field: 'ShipCountry', headerText: 'Ship Country', width: 140 }
],
aggregates: [
{
columns: [
{
type: 'Sum',
field: 'Freight',
format: 'C2',
footerTemplate: 'Sum: ${Sum}'
}
]
},
{
columns: [
{
type: 'Custom',
format: 'C2',
customAggregate: customAggregateFn,
field: 'Freight',
footerTemplate: 'Custom: ${Custom}'
}
]
}
]
});
grid.appendTo('#Grid');
|