【发布时间】:2016-08-31 04:19:19
【问题描述】:
我想弄清楚如何将我选择的行带到网格的顶部。非常重要的是我使用的是 DevExpress Asp.Net MVC GridView。
我有以下内容,这是我将几十个非解决方案混合在一起的最佳尝试。请注意 cmets:
settings.Columns.Add("customsort").Settings.SortMode =
DevExpress.XtraGrid.ColumnSortMode.Custom;
settings.CustomColumnSort += (sender, e) => {
if (e.Column.FieldName == "customsort")
{
//these following two lines are supposed to work according to the DX support team, but there is no "grid" object
bool isRow1Selected = grid.Selection.IsRowSelectedByKey(e.GetRow1Value(grid.KeyFieldName));
bool isRow2Selected = grid.Selection.IsRowSelectedByKey(e.GetRow2Value(grid.KeyFieldName));
}
e.Handled = isRow1Selected != isRow2Selected;
if (e.Handled)
{
//I don't even know whether this is right
e.Result = isRow1Selected ? 1 : -1;
}
};
简而言之,我需要将选定的行放在顶部,但我不知道如何获取我正在比较的两行或两列的选定状态。
DevEx 版本为 15.1
更新:代码示例:
settings.Columns.Add(column =>
{
//column.FieldName = "customsort";
column.FieldName = "customsort";
column.Caption = "customsort";
column.ColumnType = MVCxGridViewColumnType.Default;
//column.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
column.Settings.SortMode = DevExpress.XtraGrid.ColumnSortMode.Custom;
});
settings.CustomColumnSort += (sender, e) =>
{
var grid = (MVCxGridView)sender;
if (e.Column.FieldName == "customsort")
{
bool isRow1Selected = grid.Selection.IsRowSelectedByKey(e.GetRow1Value(grid.KeyFieldName));
bool isRow2Selected = grid.Selection.IsRowSelectedByKey(e.GetRow2Value(grid.KeyFieldName));
e.Result = isRow2Selected.CompareTo(isRow1Selected);
e.Handled = true;
}
};
如果我单击“customsort”列,它会执行回发,但排序顺序不会改变。所以至少我已经到达了某个地方,但我还没有到达那里。
【问题讨论】:
标签: asp.net-mvc devexpress-mvc