Telerik radcombobox deselect disabled items on OnClientCheckAllChecked

1 Answer 145 Views
ComboBox General Discussions
Eugene
Top achievements
Rank 1
Eugene asked on 25 Oct 2021, 02:44 PM

I have a Telerik RadComboBox that is programmatically generated in C#. In the aspx file, I have this JavaScript function which I would like to deselect any disabled comboBox item when the "Check All" choice is selected.

 

        function OnClientCheckAllChecked(sender, args) {

            var checkedItems = sender.get_checkedItems();

            for (var i = 0; i < checkedItems.length; i++) {

                console.log(checkedItems[i].get_text());

                if (checkedItems[i].get_enabled() === false) {

                    console.log("enabled is false for " + i);
                    checkedItems[i].set_checked(false);
                }
                
                console.log("checked is " + checkedItems[i].get_checked());
            }
        }

However, it does not work as intended. The disabled item is still checked after clicking the "Check All".

Here is an image of the description:

 

enter image description here

Doncho
Telerik team
commented on 28 Oct 2021, 12:33 PM

Hi Eugene,

Currently, with our recent versions, the default behavior of the CheckAll functionality of the Combo is to check only the enabled items (disabled items are not being checked when check all is clicked). Could you please clarify if the behavior on your side is different and which version of Telerik controls are you using?

For your convenience, I have attached a basic sample for testing. It would be very helpful if you modify the sample so it replicates the problem you are facing and send it back to us for troubleshooting.

Eugene
Top achievements
Rank 1
commented on 29 Oct 2021, 02:01 AM

Hi Doncho,

thanks for the demo! I am using 2014.3.1024.40 of the Telerik Web UI dll. 

After running your demo with the JavaScript code I posted originally, I could see that the script runs through only those items that were selected (ie disabled items were not selected). In my original case, the script had run through all items (enabled + disabled). Do you have any workaround for the older version of Telerik which I am using? 

1 Answer, 1 is accepted

Sort by
0
Accepted
Doncho
Telerik team
answered on 02 Nov 2021, 11:54 AM

Hi Eugene,

Thank you for the clarification!

I was able to see the described behavior in the specified version (v2014.3.1024).

Note that a lot of things have changed since 2014 and I would recommend you update to a newer version of Telerik Controls. To leverage all the features, controls, fixes, and improvements applied for that long period.

Now straight to the point:

I have researched the source code of this particular version and I noticed that the set_checked() function is not affecting the disabled items:
RadComboBoxItem.js

set_checked: function(value) {
	if (!this.get_enabled())
		return;

	this._setChecked(value);

	var combo = this.get_comboBox(),
		index = this.get_index();

	if (combo) {
		if (value)
			combo._registerCheckedIndex(index);
		else
			combo._unregisterCheckedIndex(index);

		combo._updateComboBoxText();

		if (combo._checkAllElement)
			combo._updateCheckAllState();
	}

},

Having this in mind I would suggest you the following code to work around the behavior and effectively uncheck the disable the checked items as well:

function OnClientCheckAllChecked(sender, args) {
    var combo = sender;
    var checkedItems = sender.get_checkedItems();
    for (var i = 0; i < checkedItems.length; i++) {
        console.log(checkedItems[i].get_text());
        if (checkedItems[i].get_enabled() === false) {
            var item = checkedItems[i];
            var itemIndex = item.get_index();
            item._setChecked(false);
            combo._unregisterCheckedIndex(itemIndex);
            combo._updateComboBoxText();
        }
    }
}

Please give this a try and let me know how it goes.

Kind regards,
Doncho
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Eugene
Top achievements
Rank 1
commented on 03 Nov 2021, 12:12 AM

Hi Doncho,

Thanks for helping with the workaround for the older version of Telerik, it is working now! I am now looking to upgrade the Telerik version on hand.

Best regards
Eugene

Tags
ComboBox General Discussions
Asked by
Eugene
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Share this question
or