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
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