Greetings,We connect to large data sources, with sometimes hundreds of thousands of records. To mitigate the issue of loading the entire data set into the grid, we created a custom filter to limit the SQL query to a specific month and number of transactions. The main issue is that the custom query filter (Month/transactions to return) and the grid filters are not aligned and thus the results are wrong.
So for example let’s say I have 1000 records in Jan (400 for product A and 600 for product B). In my screen I select the custom filter for Jan and select to return 500 records. The data grid is populated with 500 records. Next I use the grid filters to limit to say Product B. The grid filters the results down to just product B but it only returns 100 records. The issue here is that the SQL query is just populating the grid control based on TOP 500 records for January. The result will be 400 of product A records and 100 of product B. However, the desired result would be 500 records of Product B.
So to make this work correctly, the query would actually need to return results both on the custom filters and the grid filters. Is this possible? Or does anyone have feedback on best practices to apply in this scenario?
Thanks,Mike
Hello mheusser,
Performing this task becomes a little more difficult. The filtering is heavily reliant on the grid itself. The other example was easier because we did not use the grids filtering at all, just the ui portion of it. We were also able to retemplate the FilterCell to give us access to the value change of the editor. In this case, the list for the filters is built dynamically at runtime. However, I have put together a proof of concept example with a workaround to this. In the RecordFilterDropDownOpening event, I can change the value of the FilterDropDownItem to a command and pass in the appropriate parameter. The Command exists on my viewModel. Things to look for in this sample are GenericCommand.cs, the FilterCollectionCommand property in the MainViewModel, and the RecordFilterDropDownOpening event in the code behind. I hope this helps.
Basically, I am injecting commands in for each filteritem and then cancelling the filtering.
However, I would suggest that you submit a Feature Request for the ability to externally sort and filter the XamDataGrid as this workaround will get very complex due to different DataTypes for the fields.
Let me know if I can be any further help.
Attached Proof of Concept:
Hi
How could i extend this example and include xamdatagrid's filter icons?
That’s excellent, thanks for the help; we will give this a shot.
Mike
Hey Mike,
The XamDataGrid out of the box will not be able to support cancelling the grids filtering and doing your own filtering. It is too heavily tied to the RecordManager which will cause what you are seeing now. However, there is a way around this. You can reTemplate FilterCellValuePresenters which live inside of the FilterRow. I tried this and it seemed to work pretty well in a pretty simple proof of concept sample that I created. Here is the relevant code.
Style
<
Style TargetType="{x:Type igDP:FilterCellValuePresenter}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:FilterCellValuePresenter}">
<igEditors:XamTextEditor Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" ValueChanged="FilterCellValueChanged" Text="{TemplateBinding Content}" Tag="{TemplateBinding Field}"></igEditors:XamTextEditor></ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Event in code to filter
private
void FilterCellValueChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (e.OldValue != null)
ViewModel.FilteredPeople =
new System.Collections.ObjectModel.ObservableCollection<Person>( ViewModel.People.Where(p => p.Name.Contains(e.NewValue.ToString())));
}