Hi i have created a dynamic grid in MVC. the grid datasource will be setup in javascript.
everything works fine in creating the grid and populating the grid data if there is no grouping
However, if i want to group the record and calculate the total.The total value became "undefined".
Also, i found that in the "aggregate" in DataSourceRequest is always null. is it normal ?
@(Html.Kendo().Grid<
dynamic
>()
.Name("grid")
.Columns(columns =>
{
columns.LoadSettings((List<
GridColumnSettings
>)TempData["ColumnSettings"]);
})
.Events(e =>
{
e.DataBound("DataBound");
e.DataBinding("DataBinding");
e.ColumnMenuInit("ColumnMenuInit");
})
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.ServerOperation(false)
.PageSize(50)
.Aggregates(agg => {
var ds = (List<
System.Data.DataColumn
>)TempData["dataAgg"];
if (ds != null && ds.Count() > 0)
{
foreach (System.Data.DataColumn column in (List<
System.Data.DataColumn
>)TempData["dataAgg"])
{
agg.Add(column.ColumnName, column.DataType).Sum().Count().Max().Min();
}
}
})
.Model
(model =>
{
var ds = (List<
System.Data.DataColumn
>)TempData["dataType"];
if (ds != null && ds.Count() > 0)
{
foreach (System.Data.DataColumn column in (List<
System.Data.DataColumn
>)TempData["dataType"])
{
model.Field(column.ColumnName, column.DataType);
}
}
}
)
)
.Events(e => e.ExcelExport("ExcelExport"))
.ColumnMenu(menu => menu.Columns(false))
.Filterable(f => f.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.Contains("Contains")
.StartsWith("Starts With")
.EndsWith("Ends With")
.IsEqualTo("Exact Match"))
.ForNumber(num => num.Clear()
.IsEqualTo("Equals")
.IsGreaterThan("Greater Than")
.IsLessThan("Less Than"))
))
.Groupable()
.Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn))
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Excel(excel => excel
.FileName("MyGrid.xlsx")
.AllPages(true)
)
.Scrollable(s => s.Enabled(true).Height("auto"))
.NoRecords("There is no record")
.HtmlAttributes(new { style = "min-width:200px;max-width:900px;" })
)
the grid data will be populated from the front end
var ds = new kendo.data.DataSource({
type: "aspnetmvc-ajax",
transport: {
read: "/GetGridData?DataUid=" + DataUid,
dataType: "json"
},
schema: {
data: "Data",
total: "Total",
errors: "Errors"
},
pageSize: 20,
serverGrouping: true,
serverPaging: true,
serverFiltering: true,
serverSorting: true,
});
var grid = $("#grid").data("kendoGrid");
grid.setDataSource(ds);