Getting started in EJ2 TypeScript MultiColumn ComboBox control
28 Jul 202618 minutes to read
This section explains the steps to create a simple MultiColumn ComboBox and demonstrates the basic usage of the MultiColumn ComboBox component, using Essential® JS 2 quickstart seed repository. This seed repository is pre-configured with the Essential® JS 2 package.
This application is integrated with the
webpack.config.jsconfiguration and uses the latest version of the webpack-cli. It requires nodev14.15.0or higher. For more information about webpack and its features, refer to the webpack documentation.
Prerequisites
Ensure the following tools are installed on your machine:
Set up the development environment
Clone the Syncfusion® TypeScript (Essential® JS 2) quickstart project from GitHub in the command prompt:
git clone https://github.com/SyncfusionExamples/ej2-quickstart-webpack ej2-quickstart
Navigate to the project folder in the command prompt:
cd ej2-quickstart
Install Syncfusion® MultiColumn ComboBox package
Syncfusion® TypeScript (Essential® JS 2) packages are available on the npmjs.com public registry. You can install all Syncfusion® TypeScript (Essential® JS 2) controls in a single @syncfusion/ej2 package or individual packages for each control.
Use the following command to install the @syncfusion/ej2-multicolumn-combobox package:
npm install @syncfusion/ej2-multicolumn-combobox --save
Then, install the remaining dependent npm packages using the following command:
npm install
Import Syncfusion® MultiColumn ComboBox CSS styles
Syncfusion® JavaScript controls provide built-in themes, which are available from the npm theme packages. Additionally, themes can be loaded via CDN or customized using the Theme Studio. For more information, refer to the themes documentation.
The quickstart application is preconfigured to use the Fluent2 theme. To install the Fluent2 theme package, use the following command:
npm install @syncfusion/ej2-fluent2-theme --saveThe required styles are imported in the ~/src/styles/styles.css file, as shown below:
@import "../../node_modules/@syncfusion/ej2-fluent2-theme/styles/multicolumn-combobox/index.css";Learn more about built-in themes and individual control CSS references.
Add Syncfusion® MultiColumn ComboBox control to the application
The MultiColumn ComboBox can be initialized through three different tags select, UL and input element.
Open the application in Visual Studio Code and add the Syncfusion® TypeScript UI controls.
In this article, the MultiColumn ComboBox control is used as an example. Add the following MultiColumn ComboBox element to the ~/src/index.html file.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Essential JS 2 MultiColumn ComboBox control</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta name="description" content="Essential JS 2" />
<meta name="author" content="Syncfusion" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div id='container' style="margin:50px 0 auto; width:500px;">
<!--element which is going to render the MultiColumn ComboBox-->
<input type="text" tabindex="1" id='multicolumn' />
</div>
</body>
</html>Now, to render the MultiColumn ComboBox control, add the following TypeScript code to the ~/src/app/app.ts file.
import { MultiColumnComboBox, ColumnModel } from '@syncfusion/ej2-multicolumn-combobox';
// define the array of object data for datasource
let employeeData: {[key: string]: Object}[] = [
{ "EmpID": 1001, "Name": "Andrew Fuller", "Designation": "Team Lead", "Country": "England" },
{ "EmpID": 1002, "Name": "Robert", "Designation": "Developer", "Country": "USA" },
{ "EmpID": 1003, "Name": "John", "Designation": "Tester", "Country": "Germany" },
{ "EmpID": 1004, "Name": "Robert King", "Designation": "Product Manager", "Country": "India" },
{ "EmpID": 1005, "Name": "Steven Buchanan", "Designation": "Developer", "Country": "Italy" },
{ "EmpID": 1006, "Name": "Jane Smith", "Designation": "Developer", "Country": "Europe" },
{ "EmpID": 1007, "Name": "James Brown", "Designation": "Developer", "Country": "Australia" },
{ "EmpID": 1008, "Name": "Laura Callahan", "Designation": "Developer", "Country": "Africa" },
{ "EmpID": 1009, "Name": "Mario Pontes", "Designation": "Developer", "Country": "Russia" },
];
// define the column values for data columns
let columnsData: ColumnModel[] = [
{ field: 'EmpID', header: 'Employee ID', width: 120 },
{ field: 'Name', width: 120, header: 'Name' },
{ field: 'Designation', header: 'Designation', width: 120 },
{ field: 'Country', header: 'Country', width: 100 }
];
// initialize MultiColumn ComboBox component
let multiComboBoxObject: MultiColumnComboBox = new MultiColumnComboBox({
//set the data to dataSource property
dataSource: employeeData,
//set the column data to the columns property
columns: columnsData,
//set the fields of the multicolumn combobox
fields: { text: 'Name', value: 'EmpID' }
});
// render initialized MultiColumn ComboBox
multiComboBoxObject.appendTo('#multicolumn');Run the application
Now, run the application in the browser using the following command.
npm run start
The following example illustrates the output in your browser.
import { MultiColumnComboBox, ColumnModel } from '@syncfusion/ej2-multicolumn-combobox';
// defined the array of object data
let 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" },
];
let columnsData: ColumnModel[] = [
{ field: 'EmpID', header: 'Employee ID', width: 120 },
{ field: 'Name', header: 'Name', width: 120 },
{ field: 'Designation', header: 'Designation', width: 120 },
{ field: 'Country', header: 'Country', width: 100 }
];
// initialize MultiColumn Combobox component
let multiComboBoxObject: MultiColumnComboBox = new MultiColumnComboBox({
//set the data to dataSource property
dataSource: empData,
//set the column of the multicolumn combobox
columns: columnsData,
//set the fields of the multicolumn combobox
fields: { text: 'Name', value: 'EmpID' },
// set placeholder to ComboBox input element
placeholder: "Select a employee",
});
// render initialized MultiColumn ComboBox
multiComboBoxObject.appendTo('#multicolumn');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 MultiColumn Combobox</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="styles.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/34.2.2/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container' style="margin:50px auto 0; width:500px;">
<br>
<input type="text" tabindex="1" id='multicolumn' />
</div>
</body>
</html>Configure the popup list
By default, the width of the popup list automatically adjusts according to the MultiColumn ComboBox input element’s width, and the height of the popup list has 300px.
The height and width of the popup list can also be customized using the popupHeight and popupWidth properties respectively.
In the following sample, popup list’s width and height are configured.
import { MultiColumnComboBox, ColumnModel } from '@syncfusion/ej2-multicolumn-combobox';
// defined the array of object data
let 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" },
];
let columnsData: ColumnModel[] = [
{ field: 'EmpID', header: 'Employee ID', width: 90 },
{ field: 'Name', width: 90, header: 'Name' },
{ field: 'Designation', header: 'Designation', width: 90 },
{ field: 'Country', header: 'Country', width: 70 }
];
// initialize MultiColumn Combobox component
let multiComboBoxObject: MultiColumnComboBox = new MultiColumnComboBox({
//set the data to dataSource property
dataSource: empData,
//set the column of the multicolumn combobox
columns: columnsData,
//set the fields of the multicolumn combobox
fields: { text: 'Name', value: 'EmpID' },
// set placeholder to ComboBox input element
placeholder: "Select a employee",
// set the height of the popup element
popupHeight: '250px',
// set the width of the popup element
popupWidth: '550px',
});
// render initialized MultiColumn ComboBox
multiComboBoxObject.appendTo('#multicolumn');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 MultiColumn Combobox</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link href="styles.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/34.2.2/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='loader'>LOADING....</div>
<div id='container' style="margin:50px auto 0; width:350px;">
<br>
<input type="text" tabindex="1" id='multicolumn' />
</div>
</body>
</html>