I am trying to figure out how to bring my selected rows to the top of the grid. Very important is that I am using the DevExpress Asp.Net MVC GridView.
I have the following, which is my best attempt at mashing together literally dozens of non-solutions. Please note the comments:
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;
}
};
In short, I need to put selected rows on top, but I don't know how to get the selected state of the two rows or columns I'm comparing.
DevEx version is 15.1
UPDATE: code sample:
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;
}
};
If I click on the "customsort" column, it does perform a postback, but the sort order does not change. So at least I'm getting somewhere, but I'm not quite there yet.