I have a grid with a column that binds to a custom timer object that contains background/foreground color information as well as timer information that is presented in the cell. I also include 2 filters on the column; One shows timers that are currently going off, and the other shows timers that are either ticking or have been acknowledged. My timer class has a boolean property that represents whether or not the timer is going off, so in order to provide this filtering functionality, I had to create an implementation of ICondition that would match this property to either 'True' or 'False'. The problem with that is that when I call SaveCustomization on the grid, the filter gets save in the following format:
<XmlSerializerData Type="Name of Filter Class" Data="PD94bWwgdmVyc2lvbj0iMS4wIj8+A long sequence of characters defining the object" />
This format is not ideal, and I have attempted making that filter class implement IXmlSerializable (I can confirm that the writeXml method gets called in the debugger), but it seems this object is always serialized one extra time and wrapped in this XmlSerializerData class.
So finally my questions are as follows:
1. Is there a way to specify (in the ComparisonCondition) a property on the data object that will be compared with the value in the filter?
2. If this isn't possible and I have to implement ICondition, can I customize how this class is serialized by implementing some kind of interface? Or can I configure the grid itself to serialize this class in a better format?
It says this question was replied to last night, but I don't see any reply.
Hi Alex,
There's no way to specify what property to compare against using a ComparisonCondition and there is no way to control what the XamDataGrid serializes out. What I recommend doing is use a FilterEvaluator instead of a custom ICondition. On the field settings, there is a property called FilterEvaluator. Implementing IFilterEvaluator is pretty straight forward as there is only one method. This Evaluate method will provide you with these items:
- The comparison operator for the filter- The cell value for the current record being evaluated- The filter value- A context that contains information such as the Cell object and the current DataRecord
It is off the DataRecord that you will be able to get the row data so that you can compare against a property inside of it. Here is a basic example:
public class MyFilterEvaluator : IFilterEvaluator { public bool? Evaluate(ComparisonOperator comparisonOperator, ref object lhs, ref object rhs, ConditionEvaluationContext context) { Cell cell = (Cell)context.CurrentValue.Context; if (cell != null) { var rowData = cell.Record.DataItem; // check the selected filter value (rhs) against the row data // return true or false return true; } return true; } }
Hey Rob,
Sorry for the delayed reply. I just got a chance to test out a filter evaluator and it works great! I just replace the lhs with the property value of the data item and return null to use the default logic for the given comparison operator. I also figure out which column the current cell exists in by looking at the field's label.
Thanks for your help!