We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how to handle drag and drop ordering when there is grouping enabled?

Thread ID:

Created:

Updated:

Platform:

Replies:

132884 Sep 27,2017 02:59 AM UTC Oct 2,2017 11:41 AM UTC Xamarin.Forms 7
loading
Tags: SfDataGrid
Emil
Asked On September 27, 2017 02:59 AM UTC

I would like to know how to handle ordering rows when there is grouping enabled. 
there are 2 cases for me. 
1) Group is reordered
2) a row is ordered into another group

When I check your example in Documentation, Collection dimensions doesnt fit. It looks like sample below is for non- grouping case.  

 if (e.Reason == QueryRowDraggingReason.DragEnded)
    {
        var collection = (sender as SfDataGrid).ItemsSource as IList;
        collection.RemoveAt(e.From - 1);
        collection.Insert(e.To - 1, e.RowData);
    }

Emil
Replied On September 27, 2017 03:30 AM UTC

i am having a property called displayorder as int in model which i am using for Grouping. Therefore I need to update not only the key of row Draged and Droped but also others in the list in order to keep the order of the rows. In this scenario, I need to get the row ( rows if the draged is a Group).  How can i do this please? 


Emil
Replied On September 27, 2017 09:18 PM UTC

I could achieve this using code below. it returns all items in group and reordering works as expected but UI is not refreshed. Group headers are not refreshed. How can I achieve this? 

  var group = e.RowData as Syncfusion.Data.Group;

 

                        foreach (var Group in group.Source)

                        {


Divakar Subramaniam [Syncfusion]
Replied On September 29, 2017 08:36 AM UTC

Hi Emil, 
 
Thanks for contacting Syncfusion support. 
 
In SfDataGrid, by default, the group headers will not be refreshed if you reorder any row from one group to another. To achieve this, you need to call UpdateCaptionSummaries() method from sample level (in QueryRowDragging event). Please refer the below code snippet, 
this.dataGrid.QueryRowDragging += DataGrid_QueryRowDragging; 
 
private async void DataGrid_QueryRowDragging(object sender, QueryRowDraggingEventArgs e) 
{ 
    if (e.Reason == QueryRowDraggingReason.DragEnded) 
    { 
        // Delay is given for refreshing the view. 
        await Task.Delay(100); 
        this.dataGrid.View.TopLevelGroup.UpdateCaptionSummaries(); 
        this.dataGrid.View.Refresh(); 
    } 
} 
   
Please refer the below UG link for better understand, 
 
Please note that, the refreshed item will not be maintained if you perform view refreshing related operations like sorting, grouping (clear and add), filtering etc., While drag and drop, the modified collection will be maintained internally only for the drag and drop operations which will not affect the bound underlying collection. But if you perform view refreshing operations like Sorting, the underlying collection only be refreshed. That’s why the refreshed group headers will not maintain. 
 
We have prepared a sample based on your requirement and you can download the same from the below link, 
 
Regards, 
Divakar. 


Emil
Replied On September 29, 2017 12:44 PM UTC

Hi,

it is unfortunately not working. Doing several drag and drop sequentially throws exception below. and also it doesnt update any caption or summary


09-29 15:38:43.550 I/MonoDroid(29122): UNHANDLED EXCEPTION:

09-29 15:38:43.575 I/MonoDroid(29122): System.NullReferenceException: Object reference not set to an instance of an object.

09-29 15:38:43.575 I/MonoDroid(29122):   at Syncfusion.SfDataGrid.XForms.GridRowDragDropController.EndDragging () [0x002b2] in :0 

09-29 15:38:43.575 I/MonoDroid(29122):   at Syncfusion.SfDataGrid.XForms.GridRowDragDropController.OnDragEnded () [0x00008] in :0 

09-29 15:38:43.575 I/MonoDroid(29122):   at Syncfusion.SfDataGrid.XForms.Droid.GridCellBaseRenderer.HandleTouchForRowDragAndDrop (Android.Views.MotionEvent e) [0x000d4] in <605b15f75385441483a1ceab754f747d>:0 

09-29 15:38:43.575 I/MonoDroid(29122):   at Syncfusion.SfDataGrid.XForms.Droid.GridCellBaseRenderer.OnTouchEvent (Android.Views.MotionEvent e) [0x00008] in <605b15f75385441483a1ceab754f747d>:0 

09-29 15:38:43.575 I/MonoDroid(29122):   at Syncfusion.SfDataGrid.XForms.Droid.Renderer.GridCaptionCellRenderer.OnTouchEvent (Android.Views.MotionEvent e) [0x00000] in <605b15f75385441483a1ceab754f747d>:0 

09-29 15:38:43.575 I/MonoDroid(29122):   at Android.Views.View.n_OnTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x0000f] in :0 

09-29 15:38:43.575 I/MonoDroid(29122):   at (wrapper dynamic-method) System.Object:97f7bdbd-e21a-4b39-8553-8c90e007c27b (intptr,intptr,intptr)


Emil
Replied On September 29, 2017 09:26 PM UTC

On the other your sample for reorder the underlaying data works only when there is no grouping but how to get the actual index of the itemsource if there is a grouping?   https://help.syncfusion.com/xamarin/sfdatagrid/rowdraganddrop#reorder-the-underlying-data

 

if (e.Reason == QueryRowDraggingReason.DragEnded)
    {
        var collection = (sender as SfDataGrid).ItemsSource as IList;
        collection.RemoveAt(e.From - 1);
        collection.Insert(e.To - 1, e.RowData);
    }

Emil
Replied On September 30, 2017 08:27 PM UTC

I am trying latest version and it throws another exception if I try the code above when there is grouping


09-30 23:25:09.174 I/MonoDroid(17571): System.ArgumentOutOfRangeException: Index must be within the bounds of the List.

09-30 23:25:09.174 I/MonoDroid(17571): Parameter name: index

09-30 23:25:09.174 I/MonoDroid(17571):   at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00029] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at System.Collections.Generic.List`1[T].Insert (System.Int32 index, T item) [0x00009] in <896ad1d315ca4ba7b117efb8dacaedcf>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at Syncfusion.SfDataGrid.XForms.GridRowDragDropController.EndDragging () [0x004c2] in <fe30172fa3ba4837bfbe14fa0c90fdf2>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at Syncfusion.SfDataGrid.XForms.GridRowDragDropController.OnDragEnded () [0x00008] in <fe30172fa3ba4837bfbe14fa0c90fdf2>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at Syncfusion.SfDataGrid.XForms.Droid.GridCellBaseRenderer.HandleTouchForRowDragAndDrop (Android.Views.MotionEvent e) [0x000d4] in <605b15f75385441483a1ceab754f747d>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at Syncfusion.SfDataGrid.XForms.Droid.GridCellBaseRenderer.OnTouchEvent (Android.Views.MotionEvent e) [0x00008] in <605b15f75385441483a1ceab754f747d>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at Syncfusion.SfDataGrid.XForms.Droid.GridCellRenderer.OnTouchEvent (Android.Views.MotionEvent e) [0x00000] in <605b15f75385441483a1ceab754f747d>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at Android.Views.View.n_OnTouchEvent_Landroid_view_MotionEvent_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_e) [0x0000f] in <d278c06ad5684d6882c743a94a93ebc2>:0 

09-30 23:25:09.174 I/MonoDroid(17571):   at (wrapper dynamic-method) System.Object:bada168d-fe24-431d-8708-510ecdecbb93 (intptr,intptr,intptr)


Vimal Prabhu Manohkaran [Syncfusion]
Replied On October 2, 2017 11:41 AM UTC

Hi Emil,

Thanks for the update. Currently it is not possible in SfDataGrid to make permanent changes to the underlying collection itself based on the drag and drop changes when grouping is enabled. This is because, the indexes obtained in the drag and drop events are based on the view’s row indexes and are irrelevant to the collection’s indexes. Hence, when grouping is applied, since the data is in a sorted format, we cannot find the actual index of the dragged row in the underlying collection which will be in a unsorted manner. Also to maintain the group information and removing key entries from each group and adding in another group is also not possible with the values from the event handlers. So kindly request you to share more details on what you expect and what you want to achieve or why you want the underlying collection to change based on the drag and drop so that we can suggest you any alternative solutions if available. Also we were not able to replicate the issue of Summary information not being updated. So kindly share a working sample replicating the issue so that we can look into it.

Regards,
Vimal Prabhu
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;