This is a migrated thread and some comments may be shown as answers.

Multiselect with checkbox and with 'All' node and all items selected by default.

5 Answers 1444 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Vinod
Top achievements
Rank 1
Vinod asked on 17 Jul 2019, 09:53 AM

Hi, 

In the example below: 

https://stackblitz.com/edit/kendo-react-multiselect-checkboxes?file=app/main.jsx

I have two requirements: 

1) Can we add an 'All' item to select all items. 

2) I want to keep all the entries/options selected by default when it loads. 

 

Regards,

Vinod

 

5 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 18 Jul 2019, 07:48 AM
Hello, Vinod,

Thank you for the example.

To achieve the desired functionalities, I can suggest the following:

1) Add Select All as first value, and depending on if it is selected, set the new value of the component.

2) To set all items as selected initially, pass the entire collection as value.

I modified the provided example to showcase this:

https://stackblitz.com/edit/kendo-react-multiselect-checkboxes-eieg1p?file=app/main.jsx

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Vinod
Top achievements
Rank 1
answered on 23 Jul 2019, 01:19 PM
Hi Stefan,

From the example provided by you, I get the gist that whatever you set the Value to becomes your default selected items when the Multiselect loads for the first time. 

My followup question is how do I make some values selected when the component loads if my object is complex one that is it consists of Key value pair. 

[{key: 1, country: 'Select All'},{key: 2, country: 'India'},{key: 3, country: 'US'},{key: 4, country: 'UK'},{key: 5, country: 'Australia'}]

I am using KeyValue Pair and load Values based on the Selected Keys. 

Could I please get an example having all the values above selected by default. 
0
Stefan
Telerik team
answered on 24 Jul 2019, 10:47 AM
Hello, Vinod,

To select values initially, set them to the state variable that is bound to the value property.

Also, the MultiSelect can work with complex objects out of the box.

I modified the example to work with complex objects and to have values selected by default:

https://stackblitz.com/edit/kendo-react-multiselect-checkboxes-dqhqcr?file=app/main.jsx

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Vinod
Top achievements
Rank 1
answered on 24 Jul 2019, 01:57 PM
Also, extending the question in the thread : 

https://stackblitz.com/edit/kendo-react-multiselect-checkboxes-eieg1p?file=app/main.jsx

1) In the example provided by you in the above link, If some of the items are deselected and then the CheckBox on the 'Select All' selected, nothing happens. Note - clicking the 'Select All' row works but not on the corresponding Checkbox. 

2) If I 'Select All' and then deselect some items, then I select them back, the 'Select All' option is not selected automatically. 


Could you please address these two questions . 
0
Stefan
Telerik team
answered on 25 Jul 2019, 10:38 AM
Hello, Vinod,

I can assume that both issue occurs because once the checkbox is clicked instead of the row, the event.nativeEventTarget is different and this check fails:

event.nativeEvent.target.innerText.trim() === "Select All"

I can suggest extending the check to include the case with the checkbox:

https://stackblitz.com/edit/kendo-react-multiselect-checkboxes-eieg1p?file=app/main.jsx

Please have in mind that this is a custom code, that has to be modified for the real case. Please ensure to inspect it and test if before using it in a real application.

Regards,
Stefan
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Vinod
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Vinod
Top achievements
Rank 1
Share this question
or