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. Image for the cookie policy date

How to reorder underlying data on row ordering if there is grouping

Hi,

this is simple but if i have sfdatagrid with groupping enabled, what is the easiest way to reorder the underlying data because there are multiple scenarios

 - group 1
     -item 1
      -item 2
 -group 2
     -item 3
     -item 4
      -item 5

scenarios
1) group 2 can be moved above group 1.  CurrentRowData is group 1, RowData is group 2
2) group 1 can be moved below group 2.  CurrentRowData is item 5, RowData is group 1 
3) item 3 can be ordered below item 5. CurrentRowData  is item 5. RowData item 3
4) item 3 can be ordered below item 4. CurrentRowData  is item 5. RowData item 3
4) item 3 can be ordered below item 2. CurrentRowData  is group 2. RowData item 3
4) item 3 can be ordered below item 1. CurrentRowData  is item 2. RowData item 3

Do you see the incosistency here? especially see between case 1 and case 2. almost same ordering but data returned is different
same goes for case 3 and case 5, it makes impossible to code to detect which item is ordered where? 

Even there is a problem; I believe that your sample is also not working. see the case 3 and 4. in both case e.From and e.To are the same.
So you article case is wrong when it is the last item (regardless grouping or not). It only works if CurrentRowData  is not the last item.

  private async void SfGrid_QueryRowDragging(object sender, QueryRowDraggingEventArgs e)
        {

            try
            {
                //e.To returns the index of the current row.
                //e.From returns the index of the dragged row.
                if (e.Reason == QueryRowDraggingReason.DragEnded)
                {

                    int from = e.From;
                    int to = e.To;

5 Replies

SK Shivagurunathan Kamalakannan Syncfusion Team July 8, 2019 02:10 PM UTC

Hi Emil, 
 
Thank you for contacting Syncfusion support. 
 
Regarding this query “Do you see the incosistency here? especially see between case 1 and case 2. almost same ordering but data returned is different” 
 
We could able to replicate the issue that the inconsistence data that are returned even when the same operations are to be made. We are validating this issue, we will validate and update you further details on or before July 10, 2019. 
 
Regarding this query “see the case 3 and 4. in both case e.From and e.To are the same.” 
 
The from and to values are consistent and we could get the correct values after doing the different operations. The values are updated based on the position, we could able to replicate the issue “From and to values are same while dragging”. We have attached the sample in which we had tested. 
 
 
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us with the more details, so that it will be helpful for us to check on it and provide you the solution at the earliest.  
 
Regards, 
Shivagurunathan 



EM Emil July 8, 2019 09:39 PM UTC

Hi, 

I am able to reproduce the problem using your sample. here are steps to reproduce. please see the screenshot below.

Case 1:
     move 1- John Carter below Maria Anders. Results are below


Case 2: Drag 1-John Carter between 2-Ana and 3.Maria  Resulted values are as below



as you can see that both results are exactly the same. so how can i distinguish between these 2 cases? in other words how will my program know on which position row with John Carter was moved?


SK Shivagurunathan Kamalakannan Syncfusion Team July 9, 2019 03:05 PM UTC

Hi Emil, 
 
Thank you for the update. 
 
We are currently validating the issue. As said we will update you with further details on July 10, 2019. We appreciate your patience until then. 
 
Regards, 
Shivagurunathan 



SK Shivagurunathan Kamalakannan Syncfusion Team July 10, 2019 01:58 PM UTC

Hi Emil, 
 
Thank you for your patience 
 
We have validated the issue. We could replicate both the issues “Inconsistence data returned while dropping the rows along with grouping” and “Same index are returned while dropping positions of rows are different”.  
 
Regarding this issue : “Inconsistence data returned while dropping the rows along with grouping” 
 
While dropping the data, the CurrentRowData is the underlying object over which dragging row is placed. And the RowData is the dragging row data. While dropping we have considered the object which has been dropped and not based on the row type. So CurrentRowData will be the object over which dragging row is placed. 
 
Regarding this issue: “Same index are returned while dropping positions of rows are different” 
 
The values returned are calculated based on the position of the dragging row. We still need time to validate both the mentioned issues, Since the calculations are based on the framework. We will provide you further details on or before July 12, 2019. 
 
We appreciate your patience until then. 
 
Regards, 
Shivagurunathan 



SK Shivagurunathan Kamalakannan Syncfusion Team July 12, 2019 01:38 PM UTC

Hi Emil, 
 
Thank you for your patience. 
 
Regarding this issue : “Inconsistence data returned while dropping the rows along with grouping” 
 
As mentioned in the last update, while dropping a row we have considered the object which has been dropped over other row. So, it is a behavior that CurrentRowData will be the row which is below the dragging row.  
 
While the groups have been collapsed and if we drag and drop the row. The CurrentRowData and RowData will be group, since the below row of dragging row is a group. And if the groups are expanded and now if we drag and drop a group, the CurrentRowData will be RowData since the below row is DataRow. 
 
Either if your requirement is to distinguish that you are dropping a group below another group then you can customize by text of the dragging view, since the text of the drag view will be as “Drag above” or “Drag below” if the row is in the appropriate place of dropping.  
 
Refer the below code snippet for reference. 
 
 
public partial class MainPage : ContentPage 
{ 
               public MainPage() 
               { 
                              InitializeComponent(); 
               } 
 
               private void DataGrid_QueryRowDragging(object sender, QueryRowDraggingEventArgs e) 
               { 
                              if (e.Reason == QueryRowDraggingReason.DragEnded) 
                              {                                                                                                                        
                                             if(e.RowData is Group) 
                                             { 
                                                            var rowDragView = dataGrid.GetType().GetProperty("RowDragView", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(dataGrid) as Syncfusion.SfDataGrid.XForms.BorderView; 
                                                            var Label= ((rowDragView.Content as Grid).Children[0]); 
                                                            var text = Label.GetType().GetProperty("Text").GetValue(Label).ToString(); 
                                                             
                                                            if(text != "Cancel drop") 
                                                            { 
                                                                           //// Customize based on the requirement. 
                                                            } 
                                             }                                                            
                              } 
               } 
} 
 
 
Refer the below sample for reference. 
 
Regarding this issue: “Same index are returned while dropping positions of rows are different” 
 
Whenever the row is dropped below the last row, QueryRowDraggingEventArgs.To parameter returns the value which is same to the second last row due to some internal calculations. But you can get the index of last Dragging row using the below code example:  
 
 
public int LastIndex   
{   
    get   
    {   
        return (dataGrid.GroupColumnDescriptions.Count > 0   
            ? this.dataGrid.View.TopLevelGroup.DisplayElements.Count   
            : this.dataGrid.View.Records.Count);   
    }   
}   
   
private void DataGrid_QueryRowDragging(object sender, QueryRowDraggingEventArgs e)   
{   
    if (e.Reason == QueryRowDraggingReason.Dragging)   
    {   
        var totalHeight = dataGrid.RowColumnIndexToPoint(newRowColumnIndex(this.LastIndex, 0)).Y + this.dataGrid.RowHeight;   
        if (Math.Ceiling(e.Position.Y + (dataGrid.RowHeight * 0.45))   
            > totalHeight && e.To == LastIndex)   
        {   
            // Will hit if RowDragView move below the last row.    
        }   
    }   
}   
 
 
 
Refer the below sample for reference. 
  
Regards, 
Shivagurunathan 


Loader.
Live Chat Icon For mobile
Up arrow icon