15 Answers, 1 is accepted
RadGridView stores its current view in its Items property at all times.
For MVVM:
If you wrap your original source collection in a QueryableCollectionView, expose this QCV as a property on your view model, and then bind RadGridView.Items to this property, you will have the current view in this QueryableCollectionView inside your view model.
I hope this helps.
Ross
the Telerik team
Correction: "bind RadGridView.ItemsSource to this property."
Kind regards,Ross
the Telerik team
Thanks for the reponse it works like a charm...
Additinal inquiry: can the ViewModel be notifiedwhen the filter are in place on the gridview? can we bind a command that will be trigger if the gridview data is filtered?
Thanks in advance,
Howell
If you bind your grid to a QueryableCollectionView, when the user filters the grid you will receive these two events:
QueryableCollectionView.FilterDescriptors.CollectionChanged
QueryableCollectionView.FilterDescriptors.ItemChanged
depending on whether the user is adding/removing a column filter or he is modifying an existing one.
You can listen for these two events inside the view model and react accordingly.
Ross
the Telerik team
My solution is to keep an ObservableCollection<> in my view model, and create a view from it for binding. All actions on the underlying collection I perform on the ObservableCollection<>, and when I need the sorted/filtered collection, I pull that from the ICollectionView view instead:
ICollectionView MyCollectionView = CollectionViewSource.GetDefaultView(MyCollection); // Bind to this view
Hope this helps somebody!
I have the same need as Howell, but I also use a RadDataPager to page the grid.
This means that the Items Property of the Grid does only contain the items on the current page, but I need the filtered items from all pages. Currently I use a QueryableCollectionView and filter its SourceCollection with the help of QueryableCollectionView .Filter predicate.
Is there an easier way to access the filtered items from all pages?
Best Regards,
Christian
When using the data pager the GridView shows only one page with the loaded data and RadGridView is actually not aware that there are other items to be loaded. Therefore its Items collection represents just the items on the page and there is not a way to have any other information.
Regards,
Didie
Telerik
How can I get the visible rows in the grid, once a group is expanded?
Thanks
You can get all the items, currently visible in RadGridView, through its RadGridView.Items collection. How does this work for you?
Regards,
Didie
Telerik
I'm trying to use the solution Riku presented, but the DefaultView is never getting updated with the filter information:
public
ICollectionView WellPropertyCollection
{
get
{
if
(_WellPropertyCollection ==
null
&& WellProperties !=
null
)
{
// This works fine
//_WellPropertyCollection = new QueryableCollectionView(WellProperties);
// This always contains the full collection, and _WellPropertyCollection.Filter is null.
_WellPropertyCollection = CollectionViewSource.GetDefaultView(WellProperties);
// Tried this as well as a desperate measure, but this didn't work either.
//CollectionViewSource newSource = new CollectionViewSource();
//newSource.Source = WellProperties;
//_WellPropertyCollection = newSource.View;
}
return
_WellPropertyCollection;
}
}
If I use the QueryableCollectionView wrapper, then the list correctly contains the filtered items after a filter is applied. However, using the DefaultView, the list always contains all the items in the full list and the Filter property on the ICollectionView is never set.
Am I doing something wrong here? How can I get the filtered list in the ViewModel without introducing view-specific (Telerik) classes?
Thanks,
Louis
RadGridView and its data engine work with FilterDescriptors. You can use QueryableCollectionView in your ViewModel as ItemsSource for RadGridView. Its FilterDescriptors collection will be synched with RadGridView's and enumerating it will give you only the items that can be viewed in RadGridView at the current moment(Filtered, sorted, paged, etc.)
Regards,
Nik
Telerik
Thanks for the response. However, if you read my post and example code, you'll see that I already have it working with QueryableCollectionView. This, however, violates the MVVM design principle. I'm looking for a way to do this without introducing Telerik classes into my ViewModel.
Louis
I am not sure what exactly do you mean by This, however, violates the MVVM design principle. This is not a violation of the pattern as the QCV does not have any reference to a visual element and can be used to work with any items control.
As to using solely the DefaultView, this cannot be achieved since the DataTable class does not offer a mechanism that can be synchronized with RadGridViews.
Hope this makes sense.
Regards,
Nik
Telerik
We are using the Telerik RadGridView in our Silverlight application.
We bind an ObservableCollection<MyData> to the RadGridView.
The RadGridView allows each column to be filtered. (IsFilterable="True")
The problem is that when the [Process] button is pressed in the UI, and the ViewModel method wants to process the filtered rows, there is no way to tell which rows that the telerik RadGridView filtered. Instead, the method wants to process all rows.
How can we get the rows that the Telerik control filtered on?
Also, we are using Silverlight.
I assume that the information in the following post is related to your question here. You can access the filtered collection through the Items property of the RadGridView.
Another option is the approach suggested in this thread of wrapping your ObservableCollection in a QueryableCollectionView, exposing that through a property and then binding it the ItemsSource property of your ViewModel. Then you can access the filtered items through the QueryableCollectionView property in the ViewModel.
If you need any additional assistance, you can also open a new support ticket.
Regards,
Vladimir Stoyanov
Progress Telerik