Insert a new record does not sort. New record is always inserted at the end

Hi

When insert a new record in the observable collection of a datagrid and having the sort on a column does not insert the new record on the correct place (always as last row). No sort is done. It is also not clear to me how I could programmatically sort after insert the record.


Collection: public ObservableCollection<TimeSheetEntryObject> DayDataEntries { get; set; }
Add the item:
 // add the entry
                    var gridItem = new TimeSheetEntryObject
                    {
                        ID = item.ID,
                        Duration = (int)tr.Duration.TotalMinutes,
                        End = item.End,
                        EndTimeZoneID = item.EndTimeZoneID,
                        Start = item.Start,
                        StartTimeZoneID = item.StartTimeZoneID,
                        Notes = item.Notes,
                        Project = task?.Project?.Name,
                        Task = task?.TaskName,
                        EventTypeShortName = eventType.ShortName,
                        InfoIcon = item.Start.Date != item.End.Date ? "\uf071" : ""
                    };
                    DayDataEntries.Add(gridItem);

The grid and sort is defined in the XAML:
           <syncDataGrid:SfDataGrid x:Name="DailyGrid"
                                     VerticalOptions="FillAndExpand"
                                     HorizontalOptions="FillAndExpand"
                                     AutoGenerateColumns="False"
                                     RowHeight="33"
                                     BackgroundColor="Transparent"
                                     LiveDataUpdateMode="AllowDataShaping"
                                     AllowSorting="false"
                                     ColumnSizer="LastColumnFill"
                                     EnableDataVirtualization="True"
                                     GridTappedCommand="{Binding DailyGridTappedCommand}"
                                     ItemsSource="{Binding DayDataEntries}">

                <syncDataGrid:SfDataGrid.SortColumnDescriptions>
                    <syncDataGrid:SortColumnDescription ColumnName="Start"
                                                        SortDirection="Ascending" />
                </syncDataGrid:SfDataGrid.SortColumnDescriptions>

The sort column is a hidden column (DateTime field).


Kind Regards,

Bruno


3 Replies

KK Karthikraja Kalaimani Syncfusion Team September 29, 2021 10:08 AM UTC

Hi Bruno, 

Thank you for contacting Syncfusion support. 

We have checked the reported issue "Newly added row is not in correct place even LiveDataUpdateMde is set as AllowDataShaping" and we are unable to reproduce the issue in our end. We have attached the tested sample for your reference. We suspect that the new value might be greater than previous value of Start property in your side. So, it will added in last row. 

Sample link : https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGridDemo-1923453267.zip

Please check the sample and still if your facing the same issue ? Please modify the sample based on your scenario and revert us back with clear replication procedure because it will help us to provide a better solution asap. 

Regards,
Karthik Raja   


ZI Zimmermann October 14, 2021 10:09 AM UTC

Hi Karthik Raja   

Due to holiday absence it took a bit longer for the answer. I had a look at the example and adapted it to my situation. Where as the behaviour could be reproduced.

Following change need to be done on the MainPage.Xaml:


ion:SfDataGrid.SortColumnDescriptions>                    <syncfusion:SortColumnDescription ColumnName="Start" SortDirection="Ascending" ></syncfusion:SortColumnDescription> </syncfusion:SfDataGrid.SortColumnDescriptions> <syncfusion:SfDataGrid.Columns>
and in the file Data.cs at line 54:

                mycollect.Add(new Data { No_1 = 10 +i, No_2 = i, Text = "MyAverage3", OrderDate = new DateTime(2012,1, i), Start = new DateTime(2012, 1, i) }); // added start

In this case the sort does not work and the new items are always added at the beginning of the datagrid.


Regards,

Bruno



SY Suthi Yuvaraj Syncfusion Team October 15, 2021 11:38 AM UTC

Hi Bruno, 
  
Thank you for contacting Syncfusion support.  
  
We have checked the reported query "Insert a new record does not sort. New record is always inserted at the end” from our side. You can achieve your requirement by setting the property to AllowDataShaping in the GridLoaded event. 
  
Also we have attached the workable sample and related documentation link for you reference.   
  
Please let us know if you need further assistance.   
  
Regards,   
Suthi Yuvaraj  


Loader.
Up arrow icon