【问题标题】:ASPxGridView Group Summary Sorting - It sorts the content inside, not the summary outsideASPxGridView 组摘要排序 - 它对内部的内容进行排序,而不是对外部的摘要进行排序
【发布时间】:2012-09-06 21:00:52
【问题描述】:
【问题讨论】:
标签:
sorting
devexpress
aspxgridview
group-summaries
【解决方案1】:
这是基于this 示例的解决方法。
主要思想是创建汇总项,显示City 组内Country 列的最小值或最大值,并按此汇总值对City 组进行排序。为此,BeforeColumnSortingGrouping 事件用于更改排序行为。
这是一个例子:
<dx:ASPxGridView ...
OnBeforeColumnSortingGrouping="gridCustomers_BeforeColumnSortingGrouping">
private void SortByCountry()
{
gridCustomers.GroupSummary.Clear();
gridCustomers.GroupSummarySortInfo.Clear();
var sortOrder = gridCustomers.DataColumns["Country"].SortOrder;
SummaryItemType summaryType = SummaryItemType.None;
switch (sortOrder)
{
case ColumnSortOrder.None:
return;
break;
case ColumnSortOrder.Ascending:
summaryType = SummaryItemType.Min;
break;
case ColumnSortOrder.Descending:
summaryType = SummaryItemType.Max;
break;
}
var groupSummary = new ASPxSummaryItem("Country", summaryType);
gridCustomers.GroupSummary.Add(groupSummary);
var sortInfo = new ASPxGroupSummarySortInfo();
sortInfo.SortOrder = sortOrder;
sortInfo.SummaryItem = groupSummary;
sortInfo.GroupColumn = "City";
gridCustomers.GroupSummarySortInfo.AddRange(sortInfo);
}
protected void Page_Load(object sender, EventArgs e)
{
SortByCountry();
}
protected void gridCustomers_BeforeColumnSortingGrouping(object sender, ASPxGridViewBeforeColumnGroupingSortingEventArgs e)
{
SortByCountry();
}
【解决方案2】:
当您按列分组时,devexpress 会自动使用该列进行排序。如果不对数据进行排序,就不可能进行分组。为了克服这个问题,我们对数据源本身进行了排序,然后将该数据源应用于网格。