This is a migrated thread and some comments may be shown as answers.

Modified OrderIndex not Applied when GridColumnsReorderEvent is Cancelled

2 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 2
Luke asked on 18 Jun 2014, 04:52 PM
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:

// 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?

2 Answers, 1 is accepted

Sort by
0
Accepted
Kostadin
Telerik team
answered on 23 Jun 2014, 08:25 AM
Hello Luke,

A possible solution is to set Reorderable property to false to the columns which you do not want to be reordered. This way the reorder command will not be fired and those columns will remain static.
<telerik:GridBoundColumn DataField="Column1" HeaderText="Column1" Reorderable="false">
</telerik:GridBoundColumn>

Regards,
Kostadin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Luke
Top achievements
Rank 2
answered on 23 Jun 2014, 05:20 PM
Setting Reorderable="false" in code behind turned out to be the perfect solution for my problem.
Thank you!
Tags
Grid
Asked by
Luke
Top achievements
Rank 2
Answers by
Kostadin
Telerik team
Luke
Top achievements
Rank 2
Share this question
or