|
[app.component.html]
<ej-grid id="Grid" [dataSource]="gridData" allowGrouping="true" allowPaging="true" showSummary="true" [summaryRows]="summaryRows" showCaptionSummary="true">
<e-columns>
<e-column field="OrderID" headerText="Order ID" width="80" [textAlign]="right"></e-column>
<e-column field="CustomerID" headerText="Customer ID" width="80" [textAlign]="right"></e-column>
<e-column field="OrderDate" headerText="OrderDate" width="80" [textAlign]="right"></e-column>
<e-column field="EmployeeID" headerText="Employee ID" width="80" [textAlign]="right"></e-column>
<e-column field="Freight" format="{0:C2}" width="80" [textAlign]="right"></e-column>
</e-columns>
</ej-grid>
[app.component.ts]
export class AppComponent
{
public summaryRows=[{title: "Sum", summaryColumns: [{ summaryType: ej.Grid.SummaryType.Sum, displayColumn: "Freight", dataMember: "Freight" }]}];
public gridData = ej.DataManager({
adaptor: new ej.UrlAdaptor(), //bind data for grid.
});
GridController:
public ActionResult DataSource(DataManager dm)
{
IEnumerable DataSource = new NorthwindDataContext().OrdersViews.ToList();
DataOperations ds = new DataOperations();
DataResult result = new DataResult();
List<string> str = new List<string>();
if (dm.Group != null)
result.groupDs = DataSource; //Pass wholeset of records – For grouping
if (dm.Sorted != null)
DataSource = ds.PerformSorting(DataSource, dm.Sorted);
DataSource = ds.PerformSkip(DataSource, dm.Skip);
result.result = DataSource.AsQueryable().Take(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; }
} |
Hey,
Can you tell me what is groupDs? Simple array? But what if we have two or three columns grouped?
Moreover, do you return all records in groupDs for grouping, and later on only part of records (skip, take) for grid?
|
result.groupDs = new NorthwindDataContext().OrdersViews.Select(s => new { s.CustomerID, s.OrderID }).ToList();//Here CustomerID and OrderID are the grouped columns |
This is not solution for me as data which we pass would be millions of records - not efficient at all. There are no other ways? How about virtual scrolling? Maybe it works better and can only pass count for required groups instead of all records?