Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASPxGridView Group Summary Sorting - It sorts the content inside, not the summary outside

I have done grouping of the grid by giving groupindex to a particular column in aspxgridview.

For example, if I am grouping by means of persons name and the orders details made by that particular person would come in the detailed content when the arrow is clicked to view the content.

When I click on the header fields to sort, it is sorting the data inside the groupContent but it is not used for sorting the data of groupsummary

I am showing all the totals as a part of group summary besides the person's name.

For example if you see in the below link:

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

If you sort by company name, the content would be sorted, but the summary showing the country and sum has no means to get sorted at outside level.

Please do suggest me options to work out this problem.

Thanks.

like image 772
Ruchi Avatar asked Sep 06 '12 21:09

Ruchi


1 Answers

Here is workaround, based on this example.
The main idea is to create summary item which shows the minimum or maximum value of Country column inside City group and sort City group by this summary values. For this BeforeColumnSortingGrouping event is used to change the sorting behavior.
Here is example:

<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();
}
like image 140
nempoBu4 Avatar answered Sep 28 '22 01:09

nempoBu4