Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
143663 | Mar 30,2019 03:22 PM UTC | Apr 24,2019 10:59 AM UTC | ASP.NET Core - EJ 2 | 12 |
![]() |
Tags: DataGrid |
<e-aggregate-column field="ShipCountry" type="Custom" footerTemplate="Brazil Count:${Custom}" customAggregate="@("customAggregateFn")"></e-aggregate-column>
|
<e-aggregate-column field="ShipCountry" type="Count" footerTemplate="Count:${Count}"></e-aggregate-column>
|
public IActionResult UrlDatasource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = order;
DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0)
{
DataSource = operation.PerformSearching(DataSource, dm.Search); //Search
}
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
DataSource = operation.PerformSorting(DataSource, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
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<Orders>().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);
} |
List<string> str = new List<string>();
//As aggregate is to be displayed for “CustomerID” column, we have fetched distinct from “CustomerID” field
IEnumerable aggdata = OrdersDetails.GetAllRecords().GroupBy(o => o.CustomerID).Select(o => o.FirstOrDefault());
if (dm.Aggregates != null)
{
...
}
IEnumerable aggregate = operation.PerformSelect(aggdata, str); //Provide the distinct data(aggdata) as argument instead of “DataSource”
|
[index.cshtml]
<div>
<ejs-grid id="Grid" allowPaging="true" allowExcelExport="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update","ExcelExport" })" toolbarClick="toolbarClick" actionBegin="actionBegin" load="load">
<e-data-manager url="/Home/UrlDatasource/" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager>
<e-grid-editsettings allowEditing="true" allowDeleting="true" allowAdding="true" mode="Normal"></e-grid-editsettings>
<e-grid-aggregates>
<e-grid-aggregate>
<e-aggregate-columns>
<e-aggregate-column field="CustomerID" type="Count" footerTemplate="Cust Count: ${Count}"></e-aggregate-column> //String type column
<e-aggregate-column field="ShipCity" type="Count" footerTemplate="Count: ${Count}"></e-aggregate-column> // String type column
<e-aggregate-column field="Freight" type="Sum" footerTemplate="Avg: ${Sum}" format="C"></e-aggregate-column> // Number type column
</e-aggregate-columns>
</e-grid-aggregate>
</e-grid-aggregates>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column>
. . . .
</e-grid-columns>
</ejs-grid>
</div>
|
<div>
<ejs-grid id="Grid" allowPaging="true" created="created" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" actionBegin="actionBegin" load="load">
<e-grid-editsettings allowEditing="true" allowDeleting="true" allowAdding="true" mode="Normal"></e-grid-editsettings>
<e-grid-aggregates>
<e-grid-aggregate>
<e-aggregate-columns>
<e-aggregate-column field="OrderID" type="Count" footerTemplate="Sum: ${Count}"></e-aggregate-column>
<e-aggregate-column field="CustomerID" type="Custom" footerTemplate="Sum: ${Custom}" customAggregate="@("customAggregateFn")"></e-aggregate-column>
</e-aggregate-columns>
</e-grid-aggregate>
</e-grid-aggregates>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" validationRules="@(new { required=true})" textAlign="Right" width="120"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer Name" validationRules="@(new { required=true})" width="150"></e-grid-column>
. . . . .
</ejs-grid>
</div>
<script>
var aggregateData;
function created(args) {
//extending the default UrlAdaptor
class CustomAdaptor extends ej.data.UrlAdaptor {
processResponse(data, ds, query, xhr, request, changes) {
aggregateData = ej.data.DataUtil.distinct(data.aggregate, 'CustomerID', true);
return super.processResponse(data, ds, query, xhr, request, changes);
}
}
var grid = document.querySelector('#Grid').ej2_instances[0];
grid.dataSource = new ej.data.DataManager({
adaptor: new CustomAdaptor()
});
}
function customAggregateFn(data) {
return aggregateData.length;
}
</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.