這是基於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();
}
也許這些文章可以幫助你:[ASPxGridView - 如何排序組(http://www.devexpress.com/Support/Center/kb/p/K18508 .aspx)和[ASPxGridView - 如何通過GroupSummarySortInfo類對組進行排序](http://www.devexpress.com/Support/Center/e/E3180.aspx)。 – Filip