Table of Contents

Class ValueSort

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 ValueSort DataSource is part of the Standard EAV Data Sources. It will reorder items passing through A-Z or Z-A based on a value of each item.

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 the same items being sorted in two different ways and delivered to the target.

Example Using Multi-Sort

You can also sort multiple fields, so "first sort by xyz, then by xyz" and use different sort-orders.:

Example Using URL Parameters

...and of course you can also use url parameters to specify field-names or sort order:

Sorting Direction

For sorting direction you can use either words or numbers

  • asc/desc
  • 1/0

Programming With The ValueSort 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";

// Sort by FullName
var sortedAuthors = CreateSource<ValueSort>(allAuthors);
sortedAuthors.Attributes = "FullName";

Read also

You should find some examples in this demo App

History

  1. Introduced in EAV 3.x, 2sxc ?

API Documentation

[PublicApi]
[VisualQuery(NiceName = "Value Sort", UiHint = "Sort items by a property", Icon = "sort", Type = DataSourceType.Sort, NameId = "ToSic.Eav.DataSources.ValueSort, ToSic.Eav.DataSources", DynamicOut = false, In = new string[] { "Default*" }, ConfigurationType = "|Config ToSic.Eav.DataSources.ValueSort", HelpLink = "https://go.2sxc.org/DsValueSort")]
public sealed class ValueSort : DataSourceBase, IDataSource, IAppIdentity, IZoneIdentity, IAppIdentityLight, ICacheKey, ICacheExpiring, ITimestamped, IHasLog, IDataSourceLinkable
Inheritance
ValueSort
Implements
Inherited Members

Remarks

Had a major, breaking update in v15. Consult the guide to upgrade your custom data sources.

Properties

Attributes

The attribute whose value will be sorted by.

[Configuration]
public string Attributes { get; set; }

Property Value

string

Directions

The sorting direction like 'asc' or 'desc', can also be 0, 1

[Configuration]
public string Directions { get; set; }

Property Value

string

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

string