- Primitive Data Types
- Object Data Types
Contact Support
Value binding in DropDownList
27 Apr 20245 minutes to read
Value binding in the DropDown List control allows you to associate data values with each list item. This facilitates managing and retrieving selected values efficiently. The DropDown List component provides flexibility in binding both primitive data types and complex objects.
Primitive Data Types
The DropDown List control provides flexible binding capabilities for primitive data types like strings and numbers. You can effortlessly bind local primitive data arrays, fetch and bind data from remote sources, and even custom data binding to suit specific requirements. Bind the value of primitive data to the value property of the DropDown List.
Primitive data types include:
- String
- Number
- Boolean
- Null
The following sample shows the example for preselect values for primitive data type
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { DropDownListModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component } from '@angular/core';
import { DropDownListComponent } from '@syncfusion/ej2-angular-dropdowns';
@Component({
imports: [
FormsModule,DropDownListModule
],
standalone: true,
selector: 'app-root',
// specifies the virtual-scroll url path
templateUrl: 'virtual-scroll.html'
})
export class AppComponent {
public records: string[] = [];
constructor() {
this.records = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"];
}
// maps the appropriate column to fields property
public fields: object = { text: 'text', value: 'id' };
public value = "Item 11"
// set the placeholder to AutoComplete input
public waterMark: string = 'e.g. Item 1';
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Object Data Types
In the DropDown List control, object binding allows you to bind to a dataset of objects. When allowObjectBinding
is enabled, the value of the control will be an object of the same type as the selected item in the value property. This feature seamlessly binds arrays of objects, whether sourced locally, retrieved from remote endpoints, or customized to suit specific application needs.
The following sample shows the example for preselect values for object data type
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { DropDownListModule } from '@syncfusion/ej2-angular-dropdowns'
import { Component } from '@angular/core';
import { DropDownListComponent } from '@syncfusion/ej2-angular-dropdowns';
@Component({
imports: [
FormsModule,DropDownListModule
],
standalone: true,
selector: 'app-root',
// specifies the virtual-scroll url path
templateUrl: 'virtual-scroll.html'
})
export class AppComponent {
public records: { [key: string]: Object }[] = [];
constructor() {
for (let i: number = 1; i <= 150; i++) {
const item: { [key: string]: Object } = {
id: 'id' + i,
text: `Item ${i}`,
};
this.records.push(item);
}
}
// maps the appropriate column to fields property
public fields: object = { text: 'text', value: 'id' };
public value = {id: 'id11', text: 'Item 11'};
// set the placeholder to AutoComplete input
public waterMark: string = 'e.g. Item 1';
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));