Hi,
I use RadGridView with RadDataPager in my app. RadGridView enables users to filter currently displayed items.
Lets imagine that orders are dispalyed by date descending. There are 1000 orders, displayed 100 per page and hence 10 pages.
For simplicity lest imagine the orders 1-100 are from 2017.09, orders 101-200 are from 2017.08 and so on.
Using RadGridView a users select to filter orders where date > 2017.09.10.
On the first page (currently displayed) there will be about ~50 orders left after filtering. If the filter is still active and I start changing pages, all the pages 2,3,4...10 will be empty (since all orders from pages 2,3,4...10 are older than 2017.09.10).
Is there any way to filter the collection feeding the RadDataPager after filtering from RadGridView is applied so the page count is recalculated?
Expected:
After filtering date > 2017.09.10 I would like the page cout to equal 1 so the user knows there is no point in browsing other pages, since there is no data to be displayed.
Any tips how to achieve this?
This is something I would need:
AfterFiltersCreatedInRadGridView(eventArgs args)
{
myRadDataPager.Collection = myRadDataPager.Collection.Where(x => MatchesFilter(x, args.Filters));
}
5 Answers, 1 is accepted
Generally speaking, RadGridView performs all of its data operations over its Items collection. The filtering of the control makes no exception to the general rule. The collection will be populated only with the filtered data after the filtering is processed. You can, for example, listen for a CollectionChanged notification of the Items collection or utilize the filtering events and manipulate the RadDataPager as per your needs. Can you please give it a try?
Hopefully, this helps. In case I can be of further assistance, feel free to approach me.
Regards,
Stefan X1
Progress Telerik
Thanks for your reply,
Following you advice I've subscribed to the event `RadGridView.Items.CollectionChanged`. I would like to get the filters used by `RadGridView` and apply them to some other collection (in the final app I would like to apply those filtern on the collection attached to RadDataPager)
The problem is that `RadGridView.FilterDescriptors.CreateFilterExpression()` returns a MethodCallExpression that is not parametrizable and hence I can't use it to filter another collection.
How can I reuser the filers created by the user in the RadGridView GUI?
Here is the code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new MyDataContext();
RadGridView.Items.CollectionChanged += Items_CollectionChanged;
}
private void Items_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
//just some sample list to test filtering, in the real app `list` would be the RadDataPager.Items
var list = new List<
dynamic
>();
foreach (var index in Enumerable.Range(1, 100))
{
list.Add(new { index = index});
}
var parameter = System.Linq.Expressions.Expression.Parameter(typeof(string), "x");
var expression = (System.Linq.Expressions.MethodCallExpression) RadGridView.FilterDescriptors.CreateFilterExpression(parameter);
var filtered = list.Where(x => ((bool)Expression.Lambda(expression).Compile().DynamicInvoke(x)));
foreach (var o in filtered)
{
Debug.WriteLine(o);
}
}
Thank you for the update.
The FilteringControl of RadGridView is tightly coupled to it through the IColumnFilterDescriptor interface. Though you can customize the UI of the FilteringControl, its underlying logic processed by the FilteringViewModel is designed to satisfy the specific needs of RadGridView. It is not meant to be reused for any other collection/component. I am afraid that this is a by design implementation and we cannot commit ourselves to modifying it.
Best Regards,
Stefan X1
Progress Telerik
I have this project: https://github.com/inwenis/RadGridView_magic
It fulfils my requirements - when I use filtering in RadGridView the page count in RadDataPager is updated.
The issue is: I have no idea why this works.
Could you explain to me why using filters in RadGridView which is feed with PagedSource (containing 50 elements) some how updates the page count in RadDataPager?
RadGridView has no knowledge of RadDataPager, what is going on?
The behavior you are experiencing is the expected one. I will try to shed some light on it.
Both RadGridView and RadDataPager utilize QueryableCollectionView internally for their data operations. When you set their ItemsSource, both controls create a QCV instance under the hood which wraps the passed collection. So, indeed when RadGridView is bound to the PagedSource it is not aware of the actual RadDataPager. The two components just use the one and same instance of QCV which results in the data operations being executed only once and the two controls being synchronized.
Hopefully, this clarifies your concerns.
Have a nice weekend, Filip.
Best Regards,
Stefan
Progress Telerik