【问题标题】:ASPxGridView Group Summary Sorting - It sorts the content inside, not the summary outsideASPxGridView 组摘要排序 - 它对内部的内容进行排序,而不是对外部的摘要进行排序
【发布时间】:2012-09-06 21:00:52
【问题描述】:

我通过将 groupindex 赋予 aspxgridview 中的特定列来完成网格的分组。

例如,如果我按人员姓名进行分组,则当单击箭头查看内容时,该特定人员所做的订单详细信息将出现在详细内容中。

当我点击标题字段进行排序时,它正在对groupContent内的数据进行排序,但它不用于对groupsummary

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

例如,如果您在以下链接中看到:

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

如果您按公司名称排序,内容将被排序,但显示国家和总和的摘要无法在外部进行排序。

请给我建议解决这个问题的选项。

谢谢。

【问题讨论】:

标签: 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 会自动使用该列进行排序。如果不对数据进行排序,就不可能进行分组。为了克服这个问题,我们对数据源本身进行了排序,然后将该数据源应用于网格。

    【讨论】:

      猜你喜欢
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2023-03-16
      • 2016-05-17
      • 2011-01-24
      • 2012-05-16
      相关资源
      最近更新 更多