Changes

HowTo:Implement Custom Filtering

69 bytes added, 29 July
/* Comparison */ Restructed Open and Closed range sections into one
'''Open Range'''
<br>
Open Range denotes a single comparison, however, we are It is also possible to filter not filtering in items of for a specific date, but rather for all items with their date whose property falls after or before the user input (depending on whether a 'Starting From' or 'Ending By' comparison is implemented. An 'open' range filter is created when only one value is inputted by the user, whereas a 'closed' range has a start and end date, and must fall on or in between these two.
For range comparison, we use the [https://learn.microsoft.com/en-us/dotnet/api/system.string.compareto?view=net-9.0 Microsoft .CompareTo method]. As documented there, this method outputs a -1/0/1 depending on the compared string's location in the range. Our expression can target one output for an 'exclusive' filter (in which the inputted date is not considered for the range), however, a more likely scenario is that the user wants the inputted date included in the filter. This is why the expression in the StringFormatConverter should be defined for start date as either !=-1 or , and for end date as !=1; the instance is either should be not less than a minimum than the start date (where true would be an output of 0 or 1), or and not greater than a maximum the end date (true = -1 or 0), respectively.
The following example shows a Similar to the earlier section on [[HowTo:Implement_Custom_Filtering#Multiple_Dynamic_.28User_Inputs.29_Criteria|multiple inputs]], separate EvalExpressions are used for each half of the range, meaning that the filtering also works (as an 'Starting Fromopen Range' comparison (0 or 1filter), where the user property when only one value should be equal to or later than is inputted by the user's inputted value. If an open range filter is all that is required by the usecase, the second input and EvalExpression can simply be eliminated.
<tabs>
<tab name="UWP - Starting From">
<source lang = "xml">
<controls:EvalExpression x:Name="FilterExpressionStart_FilterExpression" Context="{Binding}" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP"> <controls:EvalExpressionParameter Name="EXP" Value="{Binding PathElementName=TagStartInput, ElementNamePath=DateInputTag, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.ToString(&quot;yyyy/MM/dd&quot;).CompareTo(&quot;{0}&quot;)!=&quot;-1&quot;'}" /> <controls:EvalExpressionParameter Name="INPUT" Value="{Binding PathElementName=TagStartInput, ElementNamePath=DateInputText}" />
</controls:EvalExpression>
<controls:EvalExpression x:Name="End_FilterExpression" Context="{Binding}" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP">
<controls:EvalExpressionParameter Name="EXP" Value="{Binding ElementName=EndInput, Path=Tag, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.ToString(&quot;yyyy/MM/dd&quot;).CompareTo(&quot;{0}&quot;)!=&quot;1&quot;'}" />
<controls:EvalExpressionParameter Name="INPUT" Value="{Binding ElementName=EndInput, Path=Text}" />
</controls:EvalExpression>
 
<controls:EvalExpression x:Name="FilterExpression" Context="{Binding}" Expression="START +&quot;&amp;&amp;&quot;+ END">
<controls:EvalExpressionParameter Name="START" Value="{Binding ElementName=Start_FilterExpression, Path=Result}" />
<controls:EvalExpressionParameter Name="END" Value="{Binding ElementName=End_FilterExpression, Path=Result}" />
</controls:EvalExpression>
</source>
</tab>
<tab name="UWP - Ending By">
<source lang = "xml">
<controls:EvalExpression x:Name="FilterExpression" Context="{Binding}" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP">
<controls:EvalExpressionParameter Name="EXP" Value="{Binding Path=Tag, ElementName=DateInput, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.ToString(&quot;yyyy/MM/dd&quot;).CompareTo(&quot;{0}&quot;)!=&quot;1&quot;'}" />
<controls:EvalExpressionParameter Name="INPUT" Value="{Binding Path=Tag, ElementName=DateInput}" />
</controls:EvalExpression>
</source>
</tab>
 <tab name="Xamarin - Starting From">
<source lang = "xml">
<controls:EvalExpression x:Key="FilterExpressionStart_FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}"> <controls:EvalExpressionParameter Name="EXP" Value="{Binding Source={x:Reference DateStringStartString}, Path=Text, Converter={StaticResource StringFormat}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.ToString(&quot;yyyy/MM/dd&quot;).CompareTo(&quot;{0}&quot;)!=&quot;-1&quot;'}" /> <controls:EvalExpressionParameter Name="INPUT" Value="{Binding Source={x:Reference DateStringStartString}, Path=Text}" /></controls:EvalExpression><controls:EvalExpression x:Key="End_FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}"> <controls:EvalExpressionParameter Name="EXP" Value="{Binding Source={x:Reference EndString}, Path=Text, Converter={StaticResource StringFormat}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.ToString(&quot;yyyy/MM/dd&quot;).CompareTo(&quot;{0}&quot;)!=&quot;1&quot;'}" /> <controls:EvalExpressionParameter Name="INPUT" Value="{Binding Source={x:Reference EndString}, Path=Text}" />
</controls:EvalExpression>
</source>
</tab>
<tab name="Xamarin - Ending By"><source lang = "xml"><controls:EvalExpression x:Key="FilterExpression" Context="{Binding}" Expression="(INPUT==null||INPUT==START +&quot;&quotamp;) ? &quotamp;true==true&quot; : EXP " Context="{Binding}+ END"> <controls:EvalExpressionParameter Name="EXPSTART" Value="{Binding Source={x:Reference DateStringStaticResource Start_FilterExpression}, Path=Text, Converter={StaticResource StringFormat}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.ToString(&quot;yyyy/MM/dd&quot;).CompareTo(&quot;{0}&quot;)!=&quot;1&quot;'Result}" /> <controls:EvalExpressionParameter Name="INPUTEND" Value="{Binding Source={x:Reference DateStringStaticResource End_FilterExpression}, Path=TextResult}" />
</controls:EvalExpression>
</source>
</tab>
{{Hint|The difference between seeking a 'Staring From' (0, 1) or 'Ending By' comparison (-1, 0) is simply defined Note the .CompareTo method used in each half of the EXP ConverterParameter ranged filter expression string, which ends with ; the start date comparison is <noWiki>!=-1</noWiki>, or whereas the end date comparison <noWiki>!=1</noWiki>, respectively.}}
</tabs>
 
 
'''Closed Range'''
For range comparison, we use the [https://learn.microsoft.com/en-us/dotnet/api/system.string.compareto?view=net-9.0 Microsoft .CompareTo method]. As documented there, this method outputs a -1/0/1 depending on the compared string's location in the range. Our expression can target one output for an 'exclusive' filter (in which the inputted date is not considered for the range), however, a more likely scenario is that the user wants the inputted date included in the filter. This is why the expression in the StringFormatConverter should be defined for start date as !=-1, and for end date as !=1; the instance should be not less than than the start date (where true would be an output of 0 or 1), and not greater than the end date (true = -1 or 0), respectively.
 
 
{{Attention|Note the .CompareTo method used in each half of the ranged filter expression! The start date comparison is !=-1, whereas the end date comparison !=1. }}
<br>
696
edits