Class ValueFilter
Return only Entities having a specific value in an Attribute/Property
The ValueFilter DataSource is part of the Standard EAV Data Sources. It will filter items based on the values - and if none are found, will optionally return a fallback-list.
How to use with the VisualQuery
When using the VisualQuery you can just drag it into your query. This is what it usually looks like:
The above example shows that 2 of the 5 items fulfilled the filters requirements.
Using Url Parameter for Filtering
You can also filter using values from the URL, like this:
Using Multiple URL Parameters
...and of course you can also use url parameters to specify field-names and value:
... or field, value and operator:
Comparison Operators
There are many operators possible - see the in-UI help bubble for that.
Using Fallback Streams
The filter will return the items which match the requirement, but sometimes none will match. This is common when you have a parameter from the Url, which may not match anything. In the simple version this looks like this:
...this previous example used a filter criteria which didn't match any items, so it resulted in delivering all. This is very useful when you want to cascade optional filters, like this:
...this example shows two filters - the first didn't match anything (it was blank), so it delivered all items, the second one then worked, and reduced the remaining items to 2.
Programming With The ValueFilter DataSource
We recommend to use the VisualQuery where possible, as it's easier to understand and is identical for C# and JavaScript. It's also better because it separates data-retrieval from visualization.
// A source which can filter by Content-Type (EntityType)
var allAuthors = CreateSource<EntityTypeFilter>();
allAuthors.TypeName = "Author";
// filter by FullName
var someAuthors = CreateSource<ValueFilter>(allAuthors);
someAuthors.Attribute = "FullName";
someAuthors.Value = "Daniel Mettler";
Read also
Demo App and further links
You should find some examples in this demo App
History
- Introduced in EAV 3.x, 2sxc ?
- Enhanced in 2sxc 8.12 with fallback
API Documentation
Inheritance
Implements
Inherited Members
Namespace: ToSic.Eav.DataSources
Assembly: ToSic.Eav.DataSources.dll
Syntax
[PublicApi_Stable_ForUseInYourCode]
[VisualQuery(NiceName = "Value Filter", UiHint = "Keep items which have a property with the expected value", Icon = "filter_list", Type = DataSourceType.Filter, NameId = "ToSic.Eav.DataSources.ValueFilter, ToSic.Eav.DataSources", In = new string[]{"Default*", "Fallback"}, DynamicOut = false, ConfigurationType = "|Config ToSic.Eav.DataSources.ValueFilter", HelpLink = "https://r.2sxc.org/DsValueFilter")]
public sealed class ValueFilter : DataSourceBase, IDataSource, IAppIdentity, IZoneIdentity, IAppIdentityLight, ICacheInfo, ICacheKey, ICacheExpiring, ITimestamped, ICanPurgeListCache, IHasLog, IDataTarget, IAppIdentitySync, IDataSourceLinkable
Remarks
Had a major, breaking update in v15. Consult the guide to upgrade your custom data sources.
Properties
| Improve this Doc View SourceAttribute
The attribute whose value will be scanned / filtered.
Declaration
[Configuration]
public string Attribute { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Languages
Language to filter for. At the moment it is not used, or it is trying to find "any"
Declaration
[Configuration(Fallback = "default")]
public string Languages { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Operator
The comparison operator, == by default, many possibilities exist depending on the original types we're comparing
Declaration
[Configuration(Fallback = "==")]
public string Operator { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Take
Amount of items to take - then stop filtering. For performance optimization.
Declaration
[Configuration]
public string Take { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Value
The filter that will be used - for example "Daniel" when looking for an entity w/the value Daniel
Declaration
[Configuration]
public string Value { get; set; }
Property Value
Type | Description |
---|---|
System.String |