Dual Listbox in React ListBox
24 Sep 20267 minutes to read
The dual React ListBox enables users to move items between two list boxes using toolbar buttons. Create a dual ListBox by configuring items in the toolbarSettings property along with the scope property.
The following operations are available in dual ListBox:
| Options | Description |
|---|---|
| moveUp | Move the selected item in the upward direction within the React ListBox. |
| moveDown | Move the selected item in the downward direction within the React ListBox. |
| moveTo | Move the selected item to the another React ListBox. |
| moveFrom | Move the selected item from one React ListBox to the another React ListBox. |
| moveAllTo | Move all the items to the another React ListBox. |
| moveAllFrom | Move all the items from one React ListBox to the another React ListBox. |
The following example illustrates how to move items from Group A to Group B React ListBox.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ListBoxComponent } from '@syncfusion/ej2-react-dropdowns';
function App() {
let groupA = [
{ "Name": "Australia", "Code": "AU" },
{ "Name": "Bermuda", "Code": "BM" },
{ "Name": "Canada", "Code": "CA" },
{ "Name": "Cameroon", "Code": "CM" },
{ "Name": "Denmark", "Code": "DK" },
{ "Name": "France", "Code": "FR" },
{ "Name": "Finland", "Code": "FI" },
{ "Name": "Germany", "Code": "DE" },
{ "Name": "Hong Kong", "Code": "HK" }
];
let groupB = [
{ "Name": "India", "Code": "IN" },
{ "Name": "Italy", "Code": "IT" },
{ "Name": "Japan", "Code": "JP" },
{ "Name": "Mexico", "Code": "MX" },
{ "Name": "Norway", "Code": "NO" },
{ "Name": "Poland", "Code": "PL" },
{ "Name": "Switzerland", "Code": "CH" },
{ "Name": "United Kingdom", "Code": "GB" },
{ "Name": "United States", "Code": "US" }
];
let fields = { text: "Name" };
let toolbar = { items: ["moveUp", "moveDown", "moveTo", "moveFrom", "moveAllTo", "moveAllFrom"] };
return (<div className="wrapper">
<div className="listbox1">
<ListBoxComponent dataSource={groupA} fields={fields} scope="#listbox" toolbarSettings={toolbar}/></div>
<div className="listbox2">
<ListBoxComponent id="listbox" dataSource={groupB} fields={fields}/>
</div>
</div>);
}
export default App;
ReactDOM.render(<App />, document.getElementById('sample'));import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { ListBoxComponent } from '@syncfusion/ej2-react-dropdowns';
function App() {
let groupA: { [key: string]: Object }[] = [
{ "Name": "Australia", "Code": "AU" },
{ "Name": "Bermuda", "Code": "BM" },
{ "Name": "Canada", "Code": "CA" },
{ "Name": "Cameroon", "Code": "CM" },
{ "Name": "Denmark", "Code": "DK" },
{ "Name": "France", "Code": "FR" },
{ "Name": "Finland", "Code": "FI" },
{ "Name": "Germany", "Code": "DE" },
{ "Name": "Hong Kong", "Code": "HK" }
];
let groupB: { [key: string]: Object }[] = [
{ "Name": "India", "Code": "IN" },
{ "Name": "Italy", "Code": "IT" },
{ "Name": "Japan", "Code": "JP" },
{ "Name": "Mexico", "Code": "MX" },
{ "Name": "Norway", "Code": "NO" },
{ "Name": "Poland", "Code": "PL" },
{ "Name": "Switzerland", "Code": "CH" },
{ "Name": "United Kingdom", "Code": "GB" },
{ "Name": "United States", "Code": "US" }
];
let fields:object = { text:"Name"}
let toolbar:object = { items:["moveUp", "moveDown", "moveTo", "moveFrom", "moveAllTo", "moveAllFrom"]}
return (
<div className="wrapper">
<div className="listbox1">
<ListBoxComponent dataSource={groupA} fields={fields} scope="#listbox" toolbarSettings={toolbar}/></div>
<div className="listbox2">
<ListBoxComponent id="listbox" dataSource={groupB} fields={fields} />
</div>
</div>
);
}
export default App;
ReactDOM.render(<App />, document.getElementById('sample'));