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.
Unfortunately, activation email could not send to your email. Please try again.

SfDataGrid throws an exception when filtering by column

Thread ID:

Created:

Updated:

Platform:

Replies:

107713 Mar 13,2013 05:34 AM Mar 15,2013 02:55 AM WinRT 4
loading
Tags: SfDataGrid
Alexey
Asked On March 13, 2013 05:34 AM

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.

 

 



TestApp_8a5c2cf9.zip

Prakash Selvaraj [Syncfusion]
Replied On March 13, 2013 08:29 AM

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.


Alexey
Replied On March 13, 2013 11:44 PM

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)


Prakash Selvaraj [Syncfusion]
Replied On March 14, 2013 08:03 AM

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.


Alexey
Replied On March 15, 2013 02:55 AM

Hello,

 

Thank you, it works!

Your company has excellent  level of support!


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;