We have a RadGrid setup in which we are rebuilding the columns each postback but want to support column reordering, so we are maintaining the OrderIndexes of the columns in a ViewState object. This approach has been working: In the ColumnsReorder server side event we load the saved OrderIndexes from viewstate and apply reordering based on the event's Source and Target, then save the modified OrderIndexes back into ViewState. In PreRender, we apply the saved OrderIndexes to the columns (see below code) and the columns show up in the expected order.
However, we have one problem: We have certain command columns that we do not want to be movable, so when the ColumnsReorder event fires and either the Source or Target is one of these command columns we cancel the event (e.Cancelled = true;). Unfortunately, when we cancel the event the grid displays the columns in the default order even though we are still applying the saved OrderIndexes to the columns in PreRender:
I've verified that the OrderIndexes are being applied to the columns even when the ColumnsReorder event is cancelled via our OnColumnsReorder method, but the grid is simply not rendered with the modified order. It seems the OrderIndex settings are ignored when the ColumnsReorder event is cancelled.
If I don't cancel the event and simply return from the OnColumnsReorder method when a command column is specified, the command column gets moved client side even though the OrderIndex for the command column wasn't modified by our code. Any subsequent column reordering after that will see the command column suddenly pop back into place because it wasn't actually moved in the OrderIndex viewstate collection.
Do you have any suggestions for this issue?
However, we have one problem: We have certain command columns that we do not want to be movable, so when the ColumnsReorder event fires and either the Source or Target is one of these command columns we cancel the event (e.Cancelled = true;). Unfortunately, when we cancel the event the grid displays the columns in the default order even though we are still applying the saved OrderIndexes to the columns in PreRender:
// Called from OnPreRender.
private void RestoreOrderIndexes()
{
// Load the OrderIndexes saved in ViewState.
var columnOrder = (Dictionary<
string
, int>)this.ViewState["GridColumnOrder"];
if (columnOrder == null)
return;
// Apply the OrderIndexes to the grid columns.
foreach (string columnName in columnOrder.Keys)
{
var gridColumn = this.MasterTableView.Columns.FindByUniqueNameSafe(columnName);
if (gridColumn != null)
gridColumn.OrderIndex = columnOrder[columnName];
}
}
I've verified that the OrderIndexes are being applied to the columns even when the ColumnsReorder event is cancelled via our OnColumnsReorder method, but the grid is simply not rendered with the modified order. It seems the OrderIndex settings are ignored when the ColumnsReorder event is cancelled.
If I don't cancel the event and simply return from the OnColumnsReorder method when a command column is specified, the command column gets moved client side even though the OrderIndex for the command column wasn't modified by our code. Any subsequent column reordering after that will see the command column suddenly pop back into place because it wasn't actually moved in the OrderIndex viewstate collection.
Do you have any suggestions for this issue?