Skip to content
Stephen Roberts edited this page Jul 1, 2014 · 19 revisions

Data Sources are used to supply a collection of Key / Label pairs to the Editor Controls (both the key and label are returned as strings).

Enum

An enum can be configured by first selecting the assembly (or App_Code folder) to reflect, and then the specific enum:

By default each enum item name and it's value are used for a label and key respectively, although this behaviour can be overridden with optional attributes:

using nuComponents.Shared.EnumDataSource;

public enum ExampleColours
{
  [EnumDataSource(Key="#FF0000")]
  Red,

  [EnumDataSource(Enabled=false)]
  Green,

  [EnumDataSource(Key="#7FFFD4", Label="Aqua Marine")]
  AuqaMarine  
}

Json

The Json Data Url specifies the source of the json to use, this can be from any url or file. To specify a file, prepend the path with ~/ The format of the json file controls how the data is extracted.

Json Formats

Array

The simplest, this format is simply a json array of native objects e.g.

[ "apples", "oranges", "pears" ]

The array's values are used for both the Label and the Key, the Options JsonPath, Key JsonPath and Label JsonPath values are ignored when the Json is in this format as they are not required.

Objects

This is slightly more complex that arrays, but allows gives greater flexibility, it utilizes JsonPath which is a similar concept to XPath for XML.

{
	"colors":[
		{
			"colorName":"red",
			"hexValue":"#f00"
		},
		{
			"colorName":"green",
			"hexValue":"#0f0"
		},
		{
			"colorName":"blue",
			"hexValue":"#00f"
		}
	]
}

Three JsonPath expressions are required to configure how key / labels are generated from the source Json. The first, Options JsonPath defines the node-set representing all of the options, whilst the remaining two, Key JsonPath and Label JsonPath are evaluated against each of these options in turn, where the first matched node value for each is used.

Lucene

Relation

Sql

Xml

The Xml Data drop down specifies the source xml to use, this can be the built-in Umbraco Content, Media or Members, or it can be from any url or file (in which case a further config field is shown).

Three XPath expressions are required to configure how key / labels are generated from the source xml. The first, Options XPath defines the node-set representing all of the options, whilst the remaining two, Key XPath and Label XPath are evaluated against each of these options in turn, where the first matched node value for each is used.

Clone this wiki locally