Kaan
Kaan

Reputation: 896

ASPxPivotGrid Sorting

I have 2 fields that can be use in row area. One of them is "ID" and the other one is "Name". When put them in to row area, it is sorted by ID, okey. But when I just putted "Name" field to there it is sorted by value.

I'm trying to sort it by ID without displaying but haven't overcome yet.

Here the documentation but it is not very clear that can solve my problem.

Does anybody know how to solve it?

EDIT: Example:

alt text http://community.devexpress.com/forums/214248/PostAttachment.aspx

Upvotes: 4

Views: 2754

Answers (1)

DevExpress Team
DevExpress Team

Reputation: 11376

Here is the code which should work for you:

private void pivotGridControl1_CustomFieldSort(object sender, DevExpress.XtraPivotGrid.PivotGridCustomFieldSortEventArgs e) {
    if(e.Field.FieldName == "Name") {
        int value1 = Convert.ToInt32(e.GetListSourceColumnValue(e.ListSourceRowIndex1, "ID"));
        int value2 = Convert.ToInt32(e.GetListSourceColumnValue(e.ListSourceRowIndex2, "ID"));
        e.Result = Comparer.Default.Compare(value1, value2);
        if(e.SortOrder == DevExpress.XtraPivotGrid.PivotSortOrder.Descending)
            e.Result = -e.Result;
        e.Handled = true;
    }
}

Does it work?

Upvotes: 1

Related Questions