ASPxGridView分组摘要排序 - 它对内部内容进行排序,而不是外部摘要。

11

我已经通过在 aspxgridview 中给某列分配 groupindex 来对网格进行分组。

例如,如果我通过人名进行分组,那么该特定人员制作的订单详细信息将在单击箭头查看内容时显示在详细内容中。

当我单击标题字段进行排序时,它会对 groupContent 中的数据进行排序,但不用于排序 groupsummary 的数据。

我将所有总计数显示为组摘要的一部分,除了人名之外。

例如,如果您查看下面的链接:

https://demos.devexpress.com/ASPxGridViewDemos/Summary/GroupSortBySummary.aspx

如果按公司名称排序,内容将会被排序,但显示国家和总数的摘要没有手段在外部级别进行排序。
请建议我解决这个问题的选项。
谢谢。

2个回答

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();
}

0

当您按列分组时,DevExpress会自动使用该列进行排序。如果不对数据进行排序,则无法进行分组。为了解决这个问题,我们已经对数据源进行了排序,然后将该数据源应用到网格中。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接