Thanks
Karthik,
I was able to reproduce the issue making slight modifications to the project you sent. In MainPage.cs I commented out the Column addition section with logic iterating through the ViewModel Dynamic Collection's first item (because that's all I need to build the dynamic data template).
I need to use data template approach because my columns are variable and I cannot configure them ahead of time. I need to build the grid programmatically. If you do this, you'll notice that sorting of OrderID is alphabetical instead of numeric.
I changed the JsonData in ViewModel.cs to this:
public const string JsonData = "[{\"OrderID\":13,\"EmployeeID\":100,\"FirstName\":'Gina',\"LastName\":'Gable'}," +
"{\"OrderID\":1,\"EmployeeID\":200,\"FirstName\":'Danielle',\"LastName\":'Rooney'}," +
"{\"OrderID\":7,\"EmployeeID\":201,\"FirstName\":'Danielle',\"LastName\":'Rooney'}," +
"{\"OrderID\":8,\"EmployeeID\":300,\"FirstName\":'Frank',\"LastName\":'Gable'},]";
Here is the modified constructor for MainPage():
public MainPage()
{
InitializeComponent();
dataGrid.ItemsSource = new QueryableViewExt(viewModel.DynamicCollection, dataGrid);
dataGrid.AutoGenerateColumns = false;
//dataGrid.Columns.Add(new GridTextColumn()
//{
// HeaderText = "Order ID",
// MappingName = "Values[OrderID]",
//});
//dataGrid.Columns.Add(new GridTextColumn()
//{
// HeaderText = "Customer ID",
// MappingName = "Values[EmployeeID]",
//});
//dataGrid.Columns.Add(new GridTextColumn()
//{
// HeaderText = "First Name",
// MappingName = "Values[FirstName]",
//});
//dataGrid.Columns.Add(new GridTextColumn()
//{
// HeaderText = "Last Name",
// MappingName = "Values[LastName]",
//});
var firstObject = viewModel.DynamicCollection.First();
foreach (KeyValuePair kvp in firstObject.Values.ToArray())
{
var templateColumn = new GridTemplateColumn()
{
HeaderText = kvp.Key,
MappingName = $"Values[{kvp.Key}]",
AllowSorting = true
};
var dataTemplate = new DataTemplate(() =>
{
var label = new SfLabel()
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center
};
label.SetBinding(SfLabel.TextProperty, $"Values[{kvp.Key}]");
return label;
});
templateColumn.CellTemplate = dataTemplate;
dataGrid.Columns.Add(templateColumn);
}
}
With the above changes, you'll notice that when you sort by OrderId you'll get: 1,13,7,8 in ascending order and 8,7,13,1 in descending order instead of 1,7,8,13 asc and 13,8,7,1 desc
Let me know if you need more details,
Adolfo