2012-02-17 140 views
0

我在代碼中創建的列,3行區,休息列區域,以及所有那些在行區域由名稱分組,我不希望任何分組/排序,因爲我按照我希望的方式在存儲過程中進行排序和分組。ASPxPivotGrid刪除自定義排序/順序

任何想法如何禁用自動分組/排序?

謝謝

回答

1

Ref:Can I disable sort?

不可能禁用排序。 PivotGridControl將數據 按相同的值分組以計算摘要。此操作需要對 數據進行排序。此外,PivotGridControl 中的每一行或列都可能與數據源中的多個記錄相關聯。在其他 的話,就沒有辦法來唯一地標識的行和列在PivotGridControl訂購 。

在這種情況下,需要通過處理ASPxPivotGrid.CustomFieldSort事件來手動排序數據。做你的排序,並在此event.Below分組的計算,我已經發布一段代碼,演示瞭如何禁用排序:

private void pivotGridControl1_CustomFieldSort(object sender, PivotGridCustomFieldSortEventArgs e) 
{ 
    e.Result = e.ListSourceRowIndex1.CompareTo(e.ListSourceRowIndex2); 
    e.Handled = true; 
} 

參考:
Disable sorting feature by row/column
How to disable sorting and filtering features
SortOrder changed event handler
Regarding Grid Default Alphabetic Sorting

PivotGridCommands.ClearSorting Property

檢查AspxPivotGrid Sorting部分以獲得計算方面的幫助。

ASPxPivotGrid的PivotGridOptionsCustomization.AllowSort選項。
字段值的排序順序由字段的PivotGridFieldBase.SortOrder屬性指定。

1

沒有辦法阻止數據排序。基本上,ASPxPivotGrid旨在執行交叉計算。爲了正確計算結果,有必要按照用於計算結果的字段對數據進行分組。爲了對數據進行分組,有必要相應地對行進行排序。例如,假設下面的列表中包含了以下數據:

Row1: Caption1; Value1 
Row2: Caption2; Value2 
Row3: Caption2; Value3 
Row4: Caption1; Value4 

如果它是構建基於標題行必要的,那麼樞紐必須對它們進行排序,否則有一種若即若離應首先顯示的標題所有。

正如可以從上面的樣品看到的,這是不可能完全禁用排序。但是,您可以將自己的自定義排序算法,並使用CustomSorting事件中,你應該調整基於當前行位置的e.Result參數:

using DevExpress.XtraPivotGrid; 
//... 
void pivotGridControl1_CustomFieldSort(object sender, PivotGridCustomFieldSortEventArgs e) { 
    e.Result = Math.Sign(e.ListSourceRowIndex2 - e.ListSourceRowIndex1); 
    e.Handled = true; 
} 

也請閱讀以下文章:Data Sorting