Value Binding
The MultiSelectTree value can be an array of either primitive (strings, numbers, or other) or complex values (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 automatically will 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 automatically will update the corresponding field from the form model after the value of the component changes.
- The MultiSelectTree does not support the simultaneous usage of the
valueproperty and thengModelvalue binding.- The MultiSelectTree does not support values which contain
\nnew line characters. The regularinputHTML DOM element which the MultiSelectTree uses internally treats\nas a regular whitespace. Therefore, when the component compares the value of theinputelement with the data item that is selected by the user, the two values differ, the value of theinputelement is actually not present in the data of the component, and the MultiSelectTree does not recognize it. To handle such issues, map the incoming data so that it contains regular whitespaces only.
When binding the MultiSelectTree value, the component provides options for:
- Using primitive values (string, number, or other)
- Using Heteregenous Data Type
- Using complex values (objects)
Primitive Values
If the value is of a primitive type, the valuePrimitive property needs to be set to true and dataItems must be provided. The value property of the dataItems will be associated with the valueField and the text to display will be extracted from the textField of the objects.
Primitive data types include:
- String
- Number
- Undefined
- Null
Heterogenous Data Type
When
valueFieldandtextFieldarestring[], always specifyvalueDepth. If you do not provide a value for the field, the MultiSelectTree will look for the first property match fromdataItemsin thevalueFieldwhich may result in incorrect value match.
Object Values
If the MultiSelectTree is bound to a dataset of objects, its value will be an object of the same type.
When the selected item is an object, always specify
valueField. If you do not a set value for the field, the MultiSelectTree will compare the items by reference, which may complicate debugging. For example, the selected value will not be applied, if it does not reference the exact passeddataobject.