This is a migrated thread and some comments may be shown as answers.

Filter on GrdiView for EntityCollection<T> (WCF RIA)

7 Answers 104 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Masoud
Top achievements
Rank 1
Masoud asked on 21 Dec 2011, 07:08 PM
Hi!

I bind a GridView to an EntityCollection like this:
<telerik:RadGridView ItemsSource="{Binding Path=Order.OrderDetials}" CanUserInsertRows="False" IsFilteringAllowed="False" >
    <telerik:RadGridView.FilterDescriptors>
        <RadDataCtrl:FilterDescriptor Member="Variant" Value="1" Operator="IsLessThan" />
    </telerik:RadGridView.FilterDescriptors>
</telerik:RadGridView>

which works fine when I bind to an order that has "pre-existing" OrderDetails.  When I am add an OrderDetail Entity to the collection with Variant being 0 it is not displayed in the GridView until I interact with the GridView, ie, re-sort the elements.  Then the new elemnt reappears.  The property Variant is of type byte.  When I remove the filter all is well and new elements are displayed as they should. 

Thank you for your help on this!

Greetings

7 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 22 Dec 2011, 10:41 AM
Hi,

This is an indication that the source collection might not be raising the CollectionChanged event. In such a case you might want to call RadGridView.Rebind when you want to re-create the view that the grid is currently displaying. Can you confirm that the EntityCollection<T> throws the correct CollectionChanged  events when you add the new entity?

Alternatively, you can try to programmatically insert the new record directly into the grid, instead of adding it to the source collection. This is described here.

In case you still have the problem, could you please try to prepare a sample runnable project and we will debug it in order to see what exactly is going on.

Thanks in advance.

Regards,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Masoud
Top achievements
Rank 1
answered on 22 Dec 2011, 10:47 AM
Hi,

thank you for the reply!

When I remove the filter from the declaration of the grid, newlly added elements are shown immediately as expected.  It is only after I add the filter that the newly added elements are first shown after interacting with the grid.  I will try and create a test project and reproduce the isseu!

Thank you!
0
Masoud
Top achievements
Rank 1
answered on 29 Dec 2011, 05:01 PM
Hi Ross,

I am sorry I am unable to create a test project, but I was able to locate the issue.  

FilterDescriptors seem to be unable to handle comparisons to properties that are of a nullable type (int? and byte? are the types I have experimented with).   I will try and summarize the steps needed to reproduce the behaviour:
- RadViewGrid is bound to a an anumeration of business objects
- The RadGridView implements a FilterDescriptor that filters on property of the business object that is nullable, for example
<RadDataCtrl:FilterDescriptor Member="NullableIntMember" Value="1" Operator="IsLessThan" />

- Comparisons with the nullable property fail.

If I change the property I use in the FilterDescriptor to a non-nullable type (see the following markup), things work fine

<RadDataCtrl:FilterDescriptor Member="IntMember" Value="1" Operator="IsLessThan" />


If I convert the nullable property to a non-nullable property the filterdescriptor works fine.  

Thank you for your help on this issue

0
Rossen Hristov
Telerik team
answered on 29 Dec 2011, 05:49 PM
Hello,

I have prepared a sample project based on your description but I am still no able to reproduce this behavior.

Can you please examine the sample project and let me know what am I doing wrong? Thanks in advance.

By the way, which version are you using?

Regards,

Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Masoud
Top achievements
Rank 1
answered on 29 Dec 2011, 09:33 PM
Hi Ross,

you aren't doing anything wrong!!!  Your example works as expected.  I adjusted your implementation to use nullable<byte> instead of nullable<int>, and it ran as expected.

And worse of all: i can only recognize two differences between your example (that functions) and my implementation:
- I am using WCF RIA, so my POCO is Entity-based, and I use EntityCollection instead of ObservableCollection
- My ItemsSource has the syntax ItemsSource={Binding Path=Parent.EntityCollection}

So if I exchange the nullable<byte> with byte, the FilterDescriptor works.  If I use the nullable<byte>, the RadGridView only recognizes that an element has been added to the source if I interact with the RadGridView (sort the elements for example).


Regards
0
Rossen Hristov
Telerik team
answered on 30 Dec 2011, 09:20 AM
Hi,

Are you using the stock DomainDataSource or RadDomainDataSource? Have you considered using our QueryableDomainServiceCollectionView? This is a special collection that allows MVVM with WCF RIA Services.

What happens if you write the query by hand and send it to the server? In fact, FilterDescriptors don't do absolutely anything. They don't filter. They are simple property bags and nothing more. The filtering information is read from them and a Where LINQ query is created and executed at runtime. Something like this:

Parent.EntityCollection.Where(item => item.NullableInt < 1)


Also, what is the version that you are using. Maybe this will not happen with the last version. I am not sure since I don't know what the exact problem is.

Is it absolutely impossible to create a stripped down version of your real project by using a samples database such as Northwind or AdventureWorks? Or you can quickly create a brand new dummy .MDF database with only two tables, one of which has this nullable byte column. Each table can have only one or two rows -- the idea is to reproduce the real world scenario.

If I can debug this behavior I bet that I will be able to solve this issue very quickly and we will save a lot of time in trying to reproduce this on our end without having all the information that we need. 

This indeed would be the fastest way to help you figure out what is going on.

All the best,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Masoud
Top achievements
Rank 1
answered on 03 Jan 2012, 01:57 PM
Hi Ross,

I found the issue!!!  I will use the Northwind example to illustrate the issue.  The filter will run against the property UnitPrice which I made nullable and the predicate is UnitPrice < 1.

The Grid ist located in a View shows the detials of the order.  The ViewModel exposes an Order entity.  The Grid is bound to Order.Order_Details.  When the user wants to add a new Order_Detail I use object iniitializer syntax:

Order_Detail newOrderDetail = new Order_Detail { Order = Order, UnitPrice = 0 };

What happens here is that the new OrderDetail is added to Order, prior to UnitPrice being set.  The filter tries to compare the value of UnitPrice to 0 and finds null.  False is returned. 

I solved the issue by seperating the instantiation of the Order_Detail and adding the new OrderDetail to the Order.  This way the filter works.

Thank you for your effort and help and my best wishes for a happy and successful 2012!







Tags
GridView
Asked by
Masoud
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Masoud
Top achievements
Rank 1
Share this question
or