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

Filtering with changing data from a DataTable

4 Answers 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 19 Jul 2010, 05:52 PM
Dear forums,

Right now I have a grid (2010.2.714.40) that uses the DefaultView of a DataTable as an ItemsSource.  Unfortunately using something other than DataTables in not an option in my scenario.  I have a custom IFilterDescriptor which lets me filter the grid based on some complicated rules.  The filter works when it is applied, but if the data in the row changes, the filter is not reapplied.  Looking at this forum post it seems like that is the expected behavior.  Regardless, I need it to work the other way.  The alternatives suggested in that thread are not viable in my situation because it is too expensive to recreate/reset the collection view (thus reapplying the filter on each row) every time a field changes.  Are there any other alternatives?

My idea for a workaround was to add a layer of abstraction between the data table and the ItemsSource and do the filtering there instead of using the Grid's built in filtering.  This is doable because the filters are created outside of the Grid's filtering UI.  My FilteredCollectionView class took the DataTable as a member, and listened for changes to the table.  With each row change event it applied the filter on the modified row, and added/removed the DataRow as necessary to an ObservableCollection<DataRow>.  I then set the Grid's ItemsSource to that ObservableCollection.  

Sadly this is not working as expected.  Whenever I try to use my collection, I get errors like these for each column:  Property <PropertyName> not defined for type DataRow at Telerik.Windows.Data.PropertyPathDescriptor.GetPropertyDescriptor(PropertyToken token, Type componentType).  

I suspect it is occurring because of the dynamic nature of DataTables/DataRows and how the grid deals with them internally; it probably knows how to handle DataRows when the ItemsSource is a DataTable, but it never expects to see DataRows in a normal collection.

Any solutions to my current workaround, or suggestions of other workarounds will be greatly appreciated.

Thanks,
Tom

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 20 Jul 2010, 05:14 AM
Hello Tom,

I believe this blog post will help in this situation.


Best wishes,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tom
Top achievements
Rank 1
answered on 20 Jul 2010, 07:26 PM
Hello Milan

Sorry, but that example doesn't really work in my case.  I am using a DataTable's DefaultView as a source, so I don't really have any business objects to work with like in the example.  All I have are DataRows so I can't really add INotifyPropertyChanged support.  Also, my grid is not editable.  The changes that I have to deal with are all occurring in the underlying data source, outside of the grid (though how the data is changed shouldn't matter I think).

More and more its looking like I have to add my own filtering layer between the datatable and the grid.  I've got this just about working, but I am experiencing the error described in my first post.

Any other suggestions?

Thanks,
Tom
0
Milan
Telerik team
answered on 20 Jul 2010, 07:31 PM
Hello Tom,

The easiest workaround that you can try is to call Rebind of RadGridView when the underlying data is changed. If that is not applicable to your scenario we would really appreciate if if you could send us your application so that we can have a closer look and try to provide a reasonable solution.

Thank you for your time.


Regards,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tom
Top achievements
Rank 1
answered on 20 Jul 2010, 09:53 PM
Hi Milan

Unfortunately that would be too slow in my case.  I think I've singled out the problem and made a sample project for you.  See support ticket #330144

Thanks Again,
Tom
Tags
GridView
Asked by
Tom
Top achievements
Rank 1
Answers by
Milan
Telerik team
Tom
Top achievements
Rank 1
Share this question
or