Class ValueFilter
- Namespace
- ToSic.Eav.DataSources
- Assembly
- ToSic.Eav.DataSources.dll
The base class for all DataSources, especially custom DataSources. It must always be inherited. It provides a lot of core functionality to get configurations, ensure caching and more.
Important: in most cases you will inherit the CustomDataSource DataSource for custom data sources.
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
[PublicApi]
[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://go.2sxc.org/DsValueFilter")]
public sealed class ValueFilter : DataSourceBase, IDataSource, IAppIdentity, IZoneIdentity, IAppIdentityLight, ICacheKey, ICacheExpiring, ITimestamped, IHasLog, IDataSourceLinkable
- Inheritance
-
ValueFilter
- Implements
- Inherited Members
Remarks
Had a major, breaking update in v15. Consult the guide to upgrade your custom data sources.
Properties
Attribute
The attribute whose value will be scanned / filtered.
[Configuration]
public string Attribute { get; set; }
Property Value
Languages
Language to filter for. At the moment it is not used, or it is trying to find "any"
[Configuration(Fallback = "default")]
public string Languages { get; set; }
Property Value
Operator
The comparison operator, == by default, many possibilities exist depending on the original types we're comparing
[Configuration(Fallback = "==")]
public string Operator { get; set; }
Property Value
Take
Amount of items to take - then stop filtering. For performance optimization.
[Configuration]
public string Take { get; set; }
Property Value
Value
The filter that will be used - for example "Daniel" when looking for an entity w/the value Daniel
[Configuration]
public string Value { get; set; }