Hello,
I need to create SfDataGrid columns in runtime. I use GridTemplateColumn with custom DataTemplate. A DataTemplate uses Converter to get value from source data object. Source object type is Windows.Data.Json.JsonObject. Data are displayed in the Grid, but when I click on a column header, the control throws following exception:
System.NullReferenceException
at Syncfusion.Linq.QueryableExtensions.GetLambdaWithComplexPropertyNullCheck(IQueryable source, String propertyName, ParameterExpression paramExpression)
at Syncfusion.Linq.QueryableExtensions.OrderBy(IQueryable source, String propertyName, Type sourceType)
at Syncfusion.WinRT.Data.QueryableCollectionView.SortQueryable(IQueryable source)
at Syncfusion.WinRT.Data.QueryableCollectionView.RefreshSort()
at Syncfusion.WinRT.Data.CollectionViewAdv.EndDeferInternal()
at Syncfusion.WinRT.Data.CollectionViewAdv.EndDefer()
at Syncfusion.WinRT.Data.CollectionViewAdv.DeferHelper.Dispose()
at Syncfusion.WinRT.Data.CollectionViewAdv.EndInit()
at Syncfusion.UI.Xaml.Grid.GridModel.MakeSort(GridColumn Column, ListSortDirection direction)
at Syncfusion.UI.Xaml.Grid.GridHeaderCellControl.Sort()
at Syncfusion.UI.Xaml.Grid.GridHeaderCellControl.OnTapped(TappedRoutedEventArgs e)
Example is in attachment.
Hi Alexey,
Thank you for using Syncfusion Products.
We have analysed your query, this issue arises due to absence of MappingName in Columns. When we click the column header the DataGrid will sort that column by using its MappingName.
You can overcome this issue by disabling the sorting feature in DataGrid as shown in the following code snippet
[Code Snippet] [XAML]
<sf:SfDataGrid x:Name="dataGrid" AllowSort="False"/> |
Or you have to reconstruct your data form JsonObject to List / ObservableCollection, then you can bind that collection to the DataGrid, with the MappingName. This will help you to enable the sorting feature in DataGrid.
Please let us know if you need further assistance.
Regards,
Prakash S.
Hello,
Thank you for fast reply.
Unfortunately, the application does not know anything about received data from a service. I can not create any class definition in design time for creation a collection of this class.
I've tried to set MappingName property of GridTemplateColumn and fill SortComparers collection of SfDataGrid, where sortComparer.PropertyName equals column.MappingName and sortComparer.Comparer is my custom implementation of IComparer<object>.
But it seems the SfDataGrid control does not use this SortComparers collection.
After all this changes, the exception has changed to following:
System.ArgumentException
at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ReadOnlyCollection`1& arguments)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments)
at Syncfusion.Linq.QueryableExtensions.OrderBy(IQueryable source, String propertyName, IComparer`1 comparer, Type sourceType)
at Syncfusion.WinRT.Data.QueryableCollectionView.SortQueryable(IQueryable source)
at Syncfusion.WinRT.Data.QueryableCollectionView.RefreshSort()
at Syncfusion.WinRT.Data.CollectionViewAdv.EndDeferInternal()
at Syncfusion.WinRT.Data.CollectionViewAdv.EndDefer()
at Syncfusion.WinRT.Data.CollectionViewAdv.DeferHelper.Dispose()
at Syncfusion.WinRT.Data.CollectionViewAdv.EndInit()
at Syncfusion.UI.Xaml.Grid.GridModel.MakeSort(GridColumn Column, ListSortDirection direction)
at Syncfusion.UI.Xaml.Grid.GridHeaderCellControl.Sort()
at Syncfusion.UI.Xaml.Grid.GridHeaderCellControl.OnTapped(TappedRoutedEventArgs e)
Hi Alexey,
Sorry for this inconvenience caused.
We have analysed your query. Since we are using reflection to get the value from the objects that are bound to the DataGrid, for that we need the proper mapping name. In your case, by using the reflection we are not able to get the value from the JsonObject. So that only while clicking the column header DataGrid will throw the exception.
But you can achieve the sorting in sample level by using an workaround. We have modified the sample based on that please fin the sample in following location.
Sample Link: TestApp.zip
In this sample we have disabled the default sorting by setting the AllowSort property to false in DataGrid and also we have removed the default header renderer and we have added new custom header renderer. In that renderer we have hooked the tapped event for the header cell control and we have implemented the sorting logic in that tapped event.
Please let us know if you need further assistance.
Regards,
Prakash S.
Hello,
Thank you, it works!
Your company has excellent level of support!