Row Reordering

7 posts, 0 answers
  1. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 10 Mar 2015 Link to this post

    Hi,

    I would like to enable row reordering in some of our grids. I've found this example quite helpful: http://demos.telerik.com/Silverlight/#GridView/RowReorder (and this looks like the same code: http://docs.telerik.com/devtools/silverlight/controls/dragdropmanager/how-to/howto-draganddrop-within-radgridview.html).

    Please advise how I could implement these:
    1. Expose an event that could be set on the grid similarly to local:RowReorderBehavior.IsEnabled="True" (e.g. local:RowReorderBehavior.RowMoved="Grid_RowMoved"). I would expect the even to be raised from RowReorderBehavior.OnDrop. This would be helpful when grid's ItemsSource is bound to a collection. Each item in our ItemsSource has a DisplayOrder property, which is used in a SortDescriptor.
    2. Indicate the drop position in the grid itself. Something like a line between the rows where the moved row will be inserted.
    Thanks in advance.
  2. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 10 Mar 2015 in reply to Mark Link to this post

    Another question related to row ordering. When an item member (a property of row's DataCotext) is updated, to which a SortDescriptor is bound, the row order does not update automatically. Calling Rebind on the grid does not seem to do anything either. Is adding and removing SortDescriptors the only way to reorder the rows in this case?
  3. DevCraft banner
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Mar 2015 Link to this post

    Hello,

    As to your questions:
    1. I am afraid we cannot suggest such an event. You can refer to our Drag and Drop examples for a further reference.
    2. You can check the definition and usage of HideDropPositionFeedbackPresenter in the mentioned help article.
    3. When RadGridView is sorted, then the order of the items cannot be changed with a simple drag and drop as it should remain ordered as defined through a SortDescriptor. Do you experience a different problem? If so, may I ask you to open a new support ticket on the matter providing some more details on the exact case?

    Regards,
    Dimitrina
    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.

     
  5. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 16 Mar 2015 in reply to Dimitrina Link to this post

    Hi Dimitrina,

    Thanks for your help.

    Regarding the third question, looks like the behaviour we are experiencing is correct - the order of items in a sorted RadGridView cannot be changed with a drag-and-drop.

    Our intention is to bind grid's ItemsSource to a collection and allow the user to reorder the items. Could you advise how this could be achieved?

    Thanks,

    Mark
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Mar 2015 Link to this post

    Hi Mark, 

    As to your question, does the approach suggested in the referred demo (http://demos.telerik.com/Silverlight/#GridView/RowReorder) not work for you? It illustrates how you can reorder the items.

    Regards,
    Dimitrina
    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.

     
  7. Mark
    Mark avatar
    29 posts
    Member since:
    Aug 2010

    Posted 17 Mar 2015 in reply to Dimitrina Link to this post

    Hi Dimitrina,

    The approach in the demo might work for us as long as the items can be displayed in the same order the next time they are loaded into the grid. For this, I we would need to save the positions of the items (likely on the item entities in the database). Please advise whether the demo can be extended to achieve this.

    Also, if there is another grid on the page bound to the same collection (ItemsSource), would it be possible to synchronise the position of the items after dragging them?

    Thanks,

    Mark
  8. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Mar 2015 Link to this post

    Hi Mark,

    The concrete implementation of the action on drop is actually up to you. Our DragDropManager is a wrapper over the WPF drag and drop events and it gives several options when any of its event is raised. In the example, we remove the item from the collection and then insert it at a specific index where it was dropped.
    private void OnDrop(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
    {
        var draggedItem = DragDropPayloadManager.GetDataFromObject(e.Data, "DraggedItem");
        var details = DragDropPayloadManager.GetDataFromObject(e.Data, "DropDetails") as DropIndicationDetails;
                    ...
     
        if (e.Effects == DragDropEffects.Move || e.Effects == DragDropEffects.All)
        {
            ((sender as RadGridView).ItemsSource as IList).Remove(draggedItem);
        }
     
        if (e.Effects != DragDropEffects.None)
        {      
            var collection = (sender as RadGridView).ItemsSource as IList;
            int index = details.DropIndex < 0 ? 0 : details.DropIndex;
            index = details.DropIndex > collection.Count - 1 ? collection.Count : index;
     
            collection.Insert(index, draggedItem);         
        }
    }

    You can also handle the case in any other way. As to persisting any order, RadGridView does not have such a built-in option. The closest example I may suggest is the GridView Serialization demo showing how to save and load different settings using the PersistenceFramework. 

    Regards,
    Dimitrina
    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.

     
Back to Top
DevCraft banner