Value Binding
The DropDownTree value can either be a primitive (strings, numbers, or other) or a complex value (objects).
To set the value, apply any of the following approaches:
- Use the
valueproperty. If the value is set through thevalueproperty, you have to hook up to thevalueChangeevent and manually update the value of thevalueproperty. - Use the
ngModelvalue binding. If the value is set by thengModelvalue binding, the framework will automatically update the corresponding field from the model after the value of the component changes. - Use the
formControlNamevalue binding available in the Reactive forms. If the value is set by theformControlNamevalue binding, the framework will automatically update the corresponding field from the form model after the value of the component changes.
The DropDownTree does not support the simultaneous usage of the
valueproperty and thengModelvalue binding.
When binding the DropDownTree value, the component provides options for:
Primitive Values
If the value is of a primitive type, the valuePrimitive property needs to be set to true and dataItem must be provided. The value property of the dataItem will be associated with the valueField and the text to display will be extracted from the textField of the objects.
Primitive data types include:
StringNumberUndefinedNull
Heterogeneous Data Type
Heterogeneous data contains items of different types at different levels of the tree hierarchy. To handle this, supply string[] values for the valueField and textField properties and assign different field names at each tree level.
The following example demonstrates how to bind the DropDownTree to heterogeneous data.
When
valueFieldandtextFieldarestring[], always specifyvalueDepth. If you do not provide a value for the field, the DropDownTree will look for the first property match fromdataItemin thevalueFieldwhich may result in an incorrect value match.
Object Values
If the DropDownTree is bound to a dataset of objects, its value will be an object of the same type.
The following example demonstrates how to bind the DropDownTree to a dataset of objects and configure it to use an object value.
The following table lists the valid configuration scenarios.
| Data Type | Value | ValuePrimitive | ValueField | ValueDepth | DataItem |
|---|---|---|---|---|---|
| Hierarchical Homogenous | primitive | true | set | Not set | Set |
| Hierarchical Homogenous | complex | Not set | set | Not set | Not set |
| Hierarchical Heterogenous | primitive | true | set [Array] | Set | Set |
| Hierarchical Heterogenous | primitive | true | set [Array] | Not set (inferred) | Set |
| Hierarchical Heterogenous | complex | Not set | set [Array] | Set | Not set |
| Hierarchical Heterogenous | complex | Not set | set [Array] | Not set (inferred) | Not set |
| Flat | primitive | true | set | Not set | Set |
| Flat | complex | Not set | set | Not set | Not set |