The multiselect dropdown is inside a modal. so while opening the modal, instead of showing the selected values, its showing 1 selected or 2 selected in the dropdown. i want to show the selected values in the multi select dropdown.
Hi Risvana,
We suggest you use the Box mode in MultiSelect component for your requirement. In Box mode, the selected items will be visualized in chip. Please refer the below documentation and sample for more details.
Documentation : https://ej2.syncfusion.com/angular/documentation/api/multi-select/#mode
Kindly try the above suggestion and let us know if this meets your requirement. if still face a problem, please share a video with your issue
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Udhaya Kumar D
I need to use the Checkbox mode itself since this is the UI I'm following. Is there any other way to display those selected values in the dropdown instead of that '2 selected' text using the CheckBox mode.
Hi Risvana,
We have checked the reported requirement. We have prepared the sample with CheckBox mode and when you select the value, the selected value will be displayed as chips. Kindly refer to the below sample.
[app.component.html]
|
<ejs-multiselect id="multiselect-checkbox" #checkbox [dataSource]="countries" [placeholder]="checkWaterMark" [fields]="checkFields" [mode]="mode" [popupHeight]="popHeight" (change)="onChange($event)" [showDropDownIcon]="true" showSelectAll="true" (select)="onSelect($event)" (focus)="onFocus($event)" (created)="onCreate($event)" (selectedAll)="onSelectedAll($event)" (removed)="onRemoved($event)" [filterBarPlaceholder]="filterPlaceholder" ></ejs-multiselect> |
[app.component.ts]
|
export class AppComponent { @ViewChild('checkbox') public mulObj: MultiSelectComponent; public mode: string; public filterPlaceholder: string; //define the data with category public countries: { [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: 'Greenland', Code: 'GL' }, { Name: 'Hong Kong', Code: 'HK' }, { 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' } ]; // map the groupBy field with category column public checkFields: Object = { text: 'Name', value: 'Code' }; // set the placeholder to the MultiSelect input public checkWaterMark: string = 'Select countries'; // set the MultiSelect popup height public popHeight: string = '350px'; ngOnInit(): void { this.mode = 'CheckBox'; this.filterPlaceholder = 'Search countries'; }
onChange(args) { if ((this.mulObj as any).viewWrapper) { (this.mulObj as any).viewWrapper.style.display = 'none'; } (this.mulObj as any).chipCollectionWrapper.style.display = 'block'; let inputPos = (this.mulObj as any).overAllWrapper.getBoundingClientRect() let popupPos = (this.mulObj as any).popupWrapper && (this.mulObj as any).popupWrapper.getBoundingClientRect(); if (inputPos && popupPos && (inputPos.top + inputPos.height > popupPos.top)) { (this.mulObj as any).popupWrapper.style.top = (inputPos.top + inputPos.height) + 'px'; } } onSelect(args) { (this.mulObj as any).addChip(args.itemData.Name, args.itemData.Code, args.e); var proxy = this; setTimeout(function () { proxy.onChange(args) }, 50) } onCreate(args) { (this.mulObj as any).chipCollectionWrapper = this.mulObj.createElement('span', { className: 'e-chips-collection', styles: 'display:none' }); (this.mulObj as any).componentWrapper.appendChild((this.mulObj as any).chipCollectionWrapper); } onFocus(args) { (this.mulObj as any).viewWrapper.style.display = 'none'; } onSelectedAll(args) { (this.mulObj as any).hidePopup(); } onRemoved(args) { var proxy = this; setTimeout(function () { proxy.onChange(args) }, 10) } } |
Sample : https://stackblitz.com/edit/angular-9endz3-nxk9vb?file=app.component.html,app.component.ts
Kindly try the above sample and let us know if this meets your requirement.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Udhaya Kumar D
Hi UdhayaKumar,
I am able to bind the data to the multi select, but now iam getting an extra comma at the end of the data. is there any way to remove that comma
Hi Risvana,
We are validating the requirement. We will update the further details in two business days (2nd September 2022).
Regards,
Udhaya Kumar D
Hi Risvana,
In the MultiSelect component, the selected values are appended correctly in the UI. If you want the selected items as a string we suggest you use instances of the component. Please refer to the below sample for more details.
document.getElementById('multiselect-checkbox').ej2_instances[0].text |
Sample : https://stackblitz.com/edit/angular-9endz3-yzqht5?file=app.component.html,app.component.ts
Kindly try the above suggestion and let us know if this meets your requirement. If we misunderstood the requirement, we request you to provide additional details about the requirement as mentioned below. This will help us validate the requirement further and provide you with a better solution.
If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Udhaya Kumar D