Jump to: navigation, search

Changes


HowTo:Implement Custom Filtering

142 bytes added, Thursday at 13:07
This page describes how to customize filtered lists that accept one or multiple user inputs as filter criteria (referred to as 'Dynamic'), alone or combined with predefined criteria(referred to as 'Static'). The following examples are based on the Children.Items collection, however, Properties or Documents can be filtered too, by adjusting the ItemsSource in the <cv:ListCollectionView> or <controls:SfDataSourceExt> in UWP or Xamarin Mobile clients respectively.
{{Attention|Are you sure you need this?<br>UBIK has a simpler out-of-the-box Property-based filtering technique for filtering child objects when one or multiple property value inputs are the only type of criteria required. See [[Property_Based_Content_Filters]]}}
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
xmlns:controls="clr-namespace:UBIK.CPL.Controls;assembly=UBIK.CPL"
=== Resources ===
For UWP, it is possible to place the EvalExpression and Collection Filter into the <Grid.Resources>, as shown below. However, for XamarinMobile clients, it is required to use the <ContentView.Resources>.For the Collection Filter, use [[XAML_Changes_in_UBIK_WinX_3.5#Filtering_by_expressions|ListCollectionView]] for UWP & [[Xamarin_XAML#FeatureRelated|Content_filtering]] for XamarinMobile:
<tabs>
{{Attention|Note that the EvalExpression in UWP requires an x:Name, which in turn requires the 'ElementName' syntax seen in the <cv:ListCollectionView>.}}
{{Attention|Note that the Converter seen in the 'EXP' EvalExpressionParameter in UWP is 'StringFormatConverter', which is different than in XamarinMobile.}}
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<ContentView.Resources>
</source>
{{Attention|Note that Unloaded attribute improves performance by preventing refiltering while navigating away from the page. This attribute should be added to all instances of controls:SfDataSourceExt in your customizing.}}
{{Hint|Note that the EvalExpression in Xamarin Mobile requires an x:Key, which in turn requires the 'StaticResource ' syntax seen in the <controls:SfDataSourceExt>.}}{{Hint|Note that the Converter seen in the 'EXP' EvalExpressionParameter in Xamarin Mobile is 'StringFormat', which is different than in UWP.}}
</tab>
</tabs>
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<Entry x:Name="NameInput"/>
=== Items control ===
An items control will likely be used for displaying filtered results, such as <controls:SelectionBoundListView> for UWP & [[Xamarin_XAML#Performance|SfListViewExt]] for XamarinMobile:
<tabs>
<tab name="UWP">
</tab>
<tab name="Mobile(Xamarin)">
<source lang="xml">
<controls:SfListViewExt
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpression x:Key="Name_FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}">
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpression x:Key="Title_FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}">
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<x:String x:Key="Static_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower()==&quot;6f73cde9-ed38-4cbd-8ca1-4597cc2ae621&quot;</x:String>
</tab>
<tab name="Mobile(Xamarin)"><br>
⛔️ '''Don't Do:'''
<source lang = "xml"><x:String x:Key="Static_FilterExpression">Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;6f73cde9-ed38-4cbd-8ca1-4597cc2ae621&quot;)==true &amp;&amp; Item.Content.MetaDefinition.UID.ToString().ToLower().Equals(&quot;4597cc2ae621-6f73cde9-ed38-4cbd-8ca1&quot;)==true</x:String>
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpressionParameter Name="EXP" Value="{Binding Source={x:Reference NameInput}, Path=Text, Converter={StaticResource StringFormat}, ConverterParameter='Item.Properties.VisibleItems[&quot;LK_GUID_PROPERTY&quot;].DisplayString.ToLower().Contains(&quot;{0}&quot;.ToLower())==true'}" />
</tabs>
A good way to inspect and test the target binding is to output it on the items UI, therefore on the ItemTemplate of your ListView, as well as to output the expressions that are being dynamically generated in your EvalExpressions, by binding the Result to the Text property of a <TextBlock> (UWP) or <Label> (XamarinMobile).
<br>
<br>
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<DatePicker x:Name="DateInput" />
</tab>
{{Attention|In both cases, it is necessary that the format of the input matches the format of the property value, which will be explained more in the Comparison section below. In the above examples, this is applied in the Tag property (UWP) or through use of a secondary control (a Label in the Xamarin Mobile example).}}
</tabs>
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<Entry x:Name="DateInput" Placeholder="Date"/>
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpression x:Key="FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}">
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpression x:Key="Start_FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}">
<controls:EvalExpressionParameter Name="EXP" Value="{Binding ElementName=DateInput, Path=Tag, Converter={StaticResource StringFormatConverter}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.DayOfWeek.ToString().Contains(&quot;{0}&quot;.ToLower())==true'}" />
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpressionParameter Name="EXP" Value="{Binding Source={x:Reference DayWeekInputString}, Path=Text, Converter={StaticResource StringFormat}, ConverterParameter='Item.PropertyItems[&quot;DATE&quot;].Value.DayOfWeek.ToString().ToLower().Contains(&quot;{0}&quot;.ToLower())==true'}" />
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<Entry x:Name="NameInput" Text="{Binding StoredProfileParameters[name]}">
</source>
The Xamarin Mobile 'Completed' event fires when the user clicks the return button on their onscreen keyboard.
</tab>
{{Hint|StringFormatConverter/StringFormat is used to format the key-value pair as required by the StoreProfileParameterCommand. The key is hardcoded into the formatted string as, for example <noWiki>'name={0}'</noWiki>. The dynamic value, in this case whatever is inputted in the text field when the edit is completed, replaces the <noWiki>{0}</noWiki> tag when the binding is evaluated (ie. when the command is executed).}}
</tab>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:EvalExpression x:Key="Name_FilterExpression" Expression="(INPUT==null||INPUT==&quot;&quot;) ? &quot;true==true&quot; : EXP " Context="{Binding}">
<tabs>
<tab name="Mobile(Xamarin)">
<source lang = "xml">
<controls:PickerExt
[[Category:Client|Custom Filtering]]
[[Category:Filtering|Custom Filtering]]
[[Category:Mobile|Implement Custom Filtering]]
[[Category:Styling|Custom Filtering]]
[[Category:WinX|Custom Filtering]]
[[Category:XAML|Implement Custom Filtering]]
[[Category:Mobile|Implement Custom Filtering]]
561
edits