- Binding local data
- Binding remote data
Contact Support
Data binding in React MultiColumn ComboBox component
14 Jun 202415 minutes to read
The MultiColumn ComboBox loads the data either from local data sources or remote data services using the dataSource property. It supports the data type of object arrays
or DataManager
.
The MultiColumn ComboBox also supports different kinds of data services such as OData, OData V4, and Web API, and data formats such as XML, JSON, and JSONP with the help of DataManager
adaptors.
Fields | Type | Description |
---|---|---|
text | string |
Specifies the display text of each list item. |
value | number or string |
Specifies the hidden data value mapped to each list item that should contain a unique value. |
groupBy | string |
Specifies the category under which the list item has to be grouped. |
The fields should be mapped correctly. Otherwise, the selected item remains undefined.
Binding local data
The local binding in the MultiColumn ComboBox allows you to connect the component to various data sources, enabling dynamic and flexible data display.
import { MultiColumnComboBoxComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-multicolumn-combobox';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// defined the array of object data
const empData = [
{ "EmpID": 1001, "Name": "Andrew Fuller", "Designation": "Team Lead", "Country": "England" },
{ "EmpID": 1002, "Name": "Robert", "Designation": "Developer", "Country": "USA" },
{ "EmpID": 1003, "Name": "Michael", "Designation": "HR", "Country": "Russia" },
{ "EmpID": 1004, "Name": "Steven Buchanan", "Designation": "Product Manager", "Country": "Ukraine" },
{ "EmpID": 1005, "Name": "Margaret Peacock", "Designation": "Developer", "Country": "Egypt" },
{ "EmpID": 1006, "Name": "Janet Leverling", "Designation": "Team Lead", "Country": "Africa" },
{ "EmpID": 1007, "Name": "Alice", "Designation": "Product Manager", "Country": "Australia" },
{ "EmpID": 1008, "Name": "Bob", "Designation": "Developer", "Country": "India" },
{ "EmpID": 1009, "Name": "John", "Designation": "Product Manager", "Country": "Ireland"},
{ "EmpID": 1010, "Name": "Mario Pontes", "Designation": "Team Lead", "Country": "South Africa" },
{ "EmpID": 1011, "Name": "Yang Wang", "Designation": "Developer", "Country": "Russia" },
{ "EmpID": 1012, "Name": "David", "Designation": "Product Manager", "Country": "Egypt" },
{ "EmpID": 1013, "Name": "Antonio Bianchi", "Designation": "Team Lead", "Country": "USA" },
{ "EmpID": 1014, "Name": "Laura", "Designation": "Developer", "Country": "England" },
{ "EmpID": 1015, "Name": "Carlos Hernandez", "Designation": "Developer", "Country": "Canada" },
{ "EmpID": 1016, "Name": "Lily", "Designation": "Product Manager", "Country": "France" },
{ "EmpID": 1017, "Name": "Tom Williams", "Designation": "Developer", "Country": "Ukraine" },
{ "EmpID": 1018, "Name": "Grace", "Designation": "Developer", "Country": "Australia" },
{ "EmpID": 1019, "Name": "Olivia", "Designation": "Team Lead", "Country": "Ireland" },
{ "EmpID": 1020, "Name": "James", "Designation": "Developer", "Country": "China" },
];
// maps the appropriate column to fields property
const fields = { text: 'Name', value: 'EmpID' };
// set text to multicolumn ComboBox input element
const text = 'Michael';
return (
// specifies the tag for render the MultiColumn ComboBox component
<MultiColumnComboBoxComponent id="multicolumn" dataSource={empData} fields={fields} text={text}>
<ColumnsDirective>
<ColumnDirective field='EmpID' header='Employee ID' width={90}></ColumnDirective>
<ColumnDirective field='Name' header='Name' width={90}></ColumnDirective>
<ColumnDirective field='Designation' header='Designation' width={90}></ColumnDirective>
<ColumnDirective field='Country' header='Country' width={70}></ColumnDirective>
</ColumnsDirective>
</MultiColumnComboBoxComponent>
);
}
ReactDOM.render(<App />, document.getElementById('multicolumn'));
import { MultiColumnComboBoxComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-multicolumn-combobox';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// defined the array of object data
const empData: { [key: string]: Object }[] = [
{ "EmpID": 1001, "Name": "Andrew Fuller", "Designation": "Team Lead", "Country": "England" },
{ "EmpID": 1002, "Name": "Robert", "Designation": "Developer", "Country": "USA" },
{ "EmpID": 1003, "Name": "Michael", "Designation": "HR", "Country": "Russia" },
{ "EmpID": 1004, "Name": "Steven Buchanan", "Designation": "Product Manager", "Country": "Ukraine" },
{ "EmpID": 1005, "Name": "Margaret Peacock", "Designation": "Developer", "Country": "Egypt" },
{ "EmpID": 1006, "Name": "Janet Leverling", "Designation": "Team Lead", "Country": "Africa" },
{ "EmpID": 1007, "Name": "Alice", "Designation": "Product Manager", "Country": "Australia" },
{ "EmpID": 1008, "Name": "Bob", "Designation": "Developer", "Country": "India" },
{ "EmpID": 1009, "Name": "John", "Designation": "Product Manager", "Country": "Ireland"},
{ "EmpID": 1010, "Name": "Mario Pontes", "Designation": "Team Lead", "Country": "South Africa" },
{ "EmpID": 1011, "Name": "Yang Wang", "Designation": "Developer", "Country": "Russia" },
{ "EmpID": 1012, "Name": "David", "Designation": "Product Manager", "Country": "Egypt" },
{ "EmpID": 1013, "Name": "Antonio Bianchi", "Designation": "Team Lead", "Country": "USA" },
{ "EmpID": 1014, "Name": "Laura", "Designation": "Developer", "Country": "England" },
{ "EmpID": 1015, "Name": "Carlos Hernandez", "Designation": "Developer", "Country": "Canada" },
{ "EmpID": 1016, "Name": "Lily", "Designation": "Product Manager", "Country": "France" },
{ "EmpID": 1017, "Name": "Tom Williams", "Designation": "Developer", "Country": "Ukraine" },
{ "EmpID": 1018, "Name": "Grace", "Designation": "Developer", "Country": "Australia" },
{ "EmpID": 1019, "Name": "Olivia", "Designation": "Team Lead", "Country": "Ireland" },
{ "EmpID": 1020, "Name": "James", "Designation": "Developer", "Country": "China" },
];
// maps the appropriate column to fields property
const fields: Object = { text: 'Name', value: 'EmpID' };
// set text to multicolumn ComboBox input element
const text: string = 'Michael';
return (
// specifies the tag for render the MultiColumn ComboBox component
<MultiColumnComboBoxComponent id="multicolumn" dataSource={empData} fields={fields} text={text}>
<ColumnsDirective>
<ColumnDirective field='EmpID' header='Employee ID' width={90}></ColumnDirective>
<ColumnDirective field='Name' header='Name' width={90}></ColumnDirective>
<ColumnDirective field='Designation' header='Designation' width={90}></ColumnDirective>
<ColumnDirective field='Country' header='Country' width={70}></ColumnDirective>
</ColumnsDirective>
</MultiColumnComboBoxComponent>
);
}
ReactDOM.render(<App />, document.getElementById('multicolumn'));
Binding remote data
The MultiColumn ComboBox supports retrieval of data from remote data services with the help of DataManager
component.
import { MultiColumnComboBoxComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-multicolumn-combobox';
import { DataManager, WebApiAdaptor } from '@syncfusion/ej2-data';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// getting the data source
const dataSource = new DataManager({
url: 'https://services.syncfusion.com/js/production/api/Employees',
adaptor: new WebApiAdaptor,
crossDomain: true
});
// maps the appropriate column to fields property
const fields = { text: 'FirstName', value: 'EmployeeID' };
// set placeholder to multicolumn ComboBox input element
const waterMark = 'Select a name';
return (
// specifies the tag for render the MultiColumn ComboBox component
<MultiColumnComboBoxComponent id="multicolumn" dataSource={dataSource} fields={fields} placeholder={waterMark} popupHeight={'230px'}>
<ColumnsDirective>
<ColumnDirective field='EmployeeID' header='Employee ID' width={120}></ColumnDirective>
<ColumnDirective field='FirstName' header='Name' width={130}></ColumnDirective>
<ColumnDirective field='Designation' header='Designation' width={120}></ColumnDirective>
<ColumnDirective field='Country' header='Country' width={90}></ColumnDirective>
</ColumnsDirective>
</MultiColumnComboBoxComponent>
);
}
ReactDOM.render(<App />, document.getElementById('multicolumn'));
import { MultiColumnComboBoxComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-multicolumn-combobox';
import { DataManager, WebApiAdaptor } from '@syncfusion/ej2-data';
import * as React from 'react';
import * as ReactDOM from 'react-dom';
function App() {
// getting the data source
const dataSource: DataManager = new DataManager({
url: 'https://services.syncfusion.com/js/production/api/Employees',
adaptor: new WebApiAdaptor,
crossDomain: true
});
// maps the appropriate column to fields property
const fields: Object = { text: 'FirstName', value: 'EmployeeID' };
// set placeholder to multicolumn ComboBox input element
const waterMark: string = 'Select a name';
return (
// specifies the tag for render the MultiColumn ComboBox component
<MultiColumnComboBoxComponent id="multicolumn" dataSource={dataSource} fields={fields} placeholder={waterMark} popupHeight={'230px'}>
<ColumnsDirective>
<ColumnDirective field='EmployeeID' header='Employee ID' width={120}></ColumnDirective>
<ColumnDirective field='FirstName' header='Name' width={130}></ColumnDirective>
<ColumnDirective field='Designation' header='Designation' width={120}></ColumnDirective>
<ColumnDirective field='Country' header='Country' width={90}></ColumnDirective>
</ColumnsDirective>
</MultiColumnComboBoxComponent>
);
}
ReactDOM.render(<App />, document.getElementById('multicolumn'));