I’ve encountered an issue with XamDataGrid when attempting to filter a template field using alternate Binding.
I am trying to Filter a field using another field(which has the real data on which the user will filter on)
In the attached solution, sorting works – however on filtering – the search text keeps disappearing (I think this is due to us changing the recordfilter field to another field at the point before which we apply the pending filter).
I have tried using a converter but that seems to break the sortcomparers as we get the converted value instead of the object.
Filtercomparers when used – don’t get called either
I have included comments in the xaml file. Can you please advise?
Hello,
Thank for your post.
I have been looking into the sample application you have provided and the functionality you are looking for.
I believe in your scenario you can create a new RecordFilter for your Salary field. You can set its Operator and Value properties based on the current RecordFilter in RecordFilterChanged event handler, then you can add this filter to the RecordFilters collection of XamDataGrid.
For example:
if (e.RecordFilter.Field.Name == "SalaryText")
{
foreach (var item in Grid.FieldLayouts[0].RecordFilters)
if (item.FieldName == "Salary")
item.Clear();
}
if ((e.RecordFilter as RecordFilter).Conditions.Count > 0)
RecordFilter salaryFilter = new RecordFilter { FieldName = "Salary" };
ComparisonCondition salaryCondition = new ComparisonCondition(((e.RecordFilter as RecordFilter).Conditions[0] as ComparisonCondition).Operator,
((e.RecordFilter as RecordFilter).Conditions[0] as ComparisonCondition).Value);
salaryFilter.Conditions.Add(salaryCondition);
Grid.FieldLayouts[0].RecordFilters.Add(salaryFilter);
I have modified your sample application in order to show you how you can implement this approach and achieve your scenario.
Please let me know if you require any further assistance regarding this matter.
Hi,
I've just ran your updated solution and whilst the filter works , the sort comparer is now broken as it receives string value rather than the object with which we can perform our sort. Isn't it possible to have both filter and sort comparer work in tandem?
Regards,
Hello Becky,
Thank you for your post.
I have been looking into it. It seems that the behavior you have reported is expected, because this way in the comparer you receive the values corresponding with this cells instead of the DataItem. In order to work your SortComparer I can suggest you to modify it. You can cast this values to double type and this way you will achieve similar behavior. I have modified your sample application in order to show you how you can implement this approach and achieve the functionality that you are looking for.
If you need any additional assistance on this matter, or if I have misunderstood you in any way please let me know.
Hi,- ni
The issue is that "100k" is just for display as there is an underlying multiplier. for eg - the actual underlying value for 10k = 10,000 and we want to sort on the underlying value not the display.
there are various conventers for manipulating the display text hence why I can't hardode to trim string but rather rely on the actual underlying value which I can only get from the data object.
please let me know if you need further clarity - thanks
Regards
I was wondering if anyone has had a chance to look into this please?
Hello Becky George-David,
Thank you for your feedback.
I have been looking further in your scenario and modified your sample application in order to show you how you can achieve your goal.
It seems that in order to filter on Field that is bound to complex types data(in your case PersonViewModel), you should implement IComparable interface in this class for your object. This way the XamDataGrid will be able to know how to filter your complex type data.
You can take a look at the following forum thread where similar approach has posted form Stefan Stoyanov:
http://www.infragistics.com/community/forums/p/70873/362589.aspx#362589
Please do not hesitate to let me know if you require any further assistance regarding this matter.
Hi Zhikov,
Your solution still relies on trimming the alphabets. We've got different conventions for how numbers are formatted and as such can't rely on trimming strings as they do not represent the actual underlying value.
Is there a workaround with the comparer that gives the actual objects for comparison?
Becky
I have been looking into it and it seems I am not sure that I understand correctly what you have in mind with ‘Your solution still relies on trimming the alphabets’, would you please provide me with example of this issue(scenario where this solution breaks the logic ), this way I would be able to further investigate this issue for you?
As I mentioned before in your case you are working with custom type data(PersonViewModel), because you have bound the Field to whole DataItem. When you filter in the custom Comparer of this field you receive the value of the cell as string, because the XamDataGrid does not know how to filter the data from custom type.
Looking forward to hearing from you.
Thank you for using Infragistics Components!
I'm also facing the same problem and sample code are given below,
<ig:TemplateField Name="PriceText" AlternateBinding="{Binding}" Label="Price"> <ig:TemplateField.Settings> <ig:FieldSettings FilterOperandUIType="TextBox" SortComparer="{StaticResource PriceComparer}"/> </ig:TemplateField.Settings> <ig:TemplateField.DisplayTemplate> <DataTemplate> <TextBlock Text="{Binding PriceText}"/> </DataTemplate> </ig:TemplateField.DisplayTemplate> </ig:TemplateField>
if I tried with filterComparer, I get only string(of class name) in comparer instead of whole object.
Could you please advise?