- Home
- Forum
- JavaScript - EJ 2
- Ej2 DropDownTree: How to allow only one checkbox selected at a time
Ej2 DropDownTree: How to allow only one checkbox selected at a time
Hello,
How to allow only one checkbox selected at a time. Below are my dropdowntree configuration:
var parentId = new ej.dropdowns.DropDownTree({ |
Below is picture that I avoid
Thank you in advance,
Ismail
SIGN IN To post a reply.
4 Replies
1 reply marked as answer
IL
Indhumathy Loganathan
Syncfusion Team
October 4, 2021 12:43 PM UTC
Hi Ismail,
Greetings from Syncfusion support.
We checked your requirement in Dropdown Tree component. We will prepare a JavaScript Dropdown Tree sample to enable single checkbox selection at a time and we will update you the sample on 6th October, 2021.
We appreciate your patience.
Regards,
Indhumathy L
IL
Indhumathy Loganathan
Syncfusion Team
October 6, 2021 02:25 PM UTC
Hi Ismail,
Thanks for your patience.
We have prepared an Angular Dropdown Tree sample to enable single checkbox selection at a time. We have used both the select and change event to identify the node selection. Based on the checkbox selection, we have updated the Dropdown Tree component value property. Refer to the below code snippet.
|
// Initialize DropDownTree component
var ddTreeObj = new ej.dropdowns.DropDownTree({
...
popupHeight: '200px',
mode: 'Delimiter',
select: onSelect,
change: valueChange,
changeOnBlur: false,
});
ddTreeObj.appendTo('#default');
var selectedValue = [];
// call the change event's function after initialized the component.
function valueChange(args) {
if (args.oldValue !== null && args.isInteracted) {
if (args.e.target.classList.contains('e-check')) {
//Update the value property with node id when checkbox is selected.
this.value = selectedValue;
} else {
if (this.value.length == 0) {
let element = this.element
.closest('.e-show-text')
.getElementsByClassName('e-overflow')[0];
element.remove();
} else {
//Empty the value property when checkbox is unselected.
this.value = [];
}
}
}
}
function onSelect(args) {
if (args.action == 'select') {
//set id of the selected node.
selectedValue = [args.itemData.id];
} else if (args.itemData.selected) {
let proxy = this;
setTimeout(() => {
if (args.itemData.isChecked == 'true') {
selectedValue = [args.itemData.id];
//Update the value property with node id when checkbox is selected.
proxy.value = selectedValue;
} else {
//Empty the value property when checkbox is unselected.
proxy.value = [];
}
}, 5);
}
} |
Please check the sample and get back to us if you need any further assistance.
Regards,
Indhumathy L
Marked as answer
Hi Indhumathy,
Thank you for your update. Your provided sample solve my problem perfectly:
Thank you for your effort!
Best regards,
Ismail
KR
Keerthana Rajendran
Syncfusion Team
October 8, 2021 05:15 AM UTC
Hi Ismail,
Most welcome. We are glad to hear that the provided sample helped you. Please get back to us if you need any further assistance.
Regards,
Keerthana R.
SIGN IN To post a reply.
- 4 Replies
- 3 Participants
- Marked answer
-
IH ISMAIL HAMZAH
- Oct 2, 2021 09:13 AM UTC
- Oct 8, 2021 05:15 AM UTC