- Home
- Forum
- Xamarin.Forms
- how to handle drag and drop ordering when there is grouping enabled?
how to handle drag and drop ordering when there is grouping enabled?
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);
}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?
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)
{
|
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();
}
} |
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
09-29 15:38:43.575 I/MonoDroid(29122): at Syncfusion.SfDataGrid.XForms.GridRowDragDropController.OnDragEnded () [0x00008] in
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
09-29 15:38:43.575 I/MonoDroid(29122): at (wrapper dynamic-method) System.Object:97f7bdbd-e21a-4b39-8553-8c90e007c27b (intptr,intptr,intptr)
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);
}
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)
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
- 7 Replies
- 3 Participants
-
EM Emil
- Sep 27, 2017 02:59 AM UTC
- Oct 2, 2017 11:41 AM UTC