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

Checkall when disabled items

4 Answers 73 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Sonia
Top achievements
Rank 1
Sonia asked on 15 Oct 2014, 10:53 AM
Disabled items of a ComboBox should be ignored when "Check all" is clicked or not.
How can i achieve that? because the default behaviour does not take it in consideration.

4 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 20 Oct 2014, 10:10 AM
Hello,

Please use the following workaround in order to fix this behavior.

//JavaScript
var $T = $T = Telerik.Web.UI;
            $T.RadComboBox.prototype._onCheckAllItemsCheck = function (e) {
                var target = $telerik.getTouchTarget(e),
                    items = this.get_items(),
                    args = {
                        checked: this._allChecked,
                        domEvent: e
                    };
 
                if (target.nodeName == "LABEL") {
                    e.preventDefault();
                }
 
                //When the event is canceled the default behavior should be prevented,
                //otherwise the checkbox will be checked when clicked.
                if (this.raise_onCheckAllChecking(args)) {
                    e.preventDefault();
                    return;
                }
 
                this._checkedIndices = [];
                this._allChecked = !this._allChecked;
 
                for (var i = 0, length = items.get_count() ; i < length; i++) {
                     
                    if (this.get_items().getItem(i).get_enabled()) {
                        this.get_items().getItem(i)._setChecked(this._allChecked);
                    }         
                }
 
                this._updateCheckAllState();
                this._updateCheckedIndices();
                this._updateComboBoxText();
 
                args.checked = this._allChecked;
                this.raise_onCheckAllChecked(args);
 
                if (this._postBackOnCheckAllCheck) {
                    var command = {
                        Command: "CheckAll",
                        CheckAllChecked: this._allChecked
                    };
                    this.postback(command);
                }
            };
 
            $T.RadComboBox.prototype._updateCheckAllState = function () {
                 
                // check/uncheck the Check All checkbox when item checked state is changed
                var itemsCount = this.get_items().get_count(),
                    checkedItemsCount = this.get_checkedItems().length,
                    $checkAllCheckBox = $(this.get_checkAllCheckBox()),
                    enabledItemsCount = 0;
 
                for (var i = 0; i < itemsCount; i++) {
                    if (this.get_items().getItem(i).get_enabled()) {
                        enabledItemsCount++;
                    }
                }
 
                if (enabledItemsCount > 0 && checkedItemsCount == enabledItemsCount) {
                    $checkAllCheckBox.prop("checked", true);
                    this._allChecked = true;
                }
                else {
                    $checkAllCheckBox.prop("checked", false);
                    this._allChecked = false;
                }
            };



Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Sonia
Top achievements
Rank 1
answered on 20 Oct 2014, 10:20 AM
Hi Boyan,
this is not the most appropiate solution, it should be implemented by the RadComboBox class.

As it seems that this behaviour is not implemented yet,
i have tried to copy & paste your solution but i get the following JavaScript error: 'Telerik' is undefined.

​
0
Accepted
Boyan Dimitrov
Telerik team
answered on 23 Oct 2014, 09:01 AM
Hello,

We are aware of this problem and here is the public item related to this bug. You can track its progress or vote for it.

Please use the workaround in the attached file as a solution until this problem is fixed.

Regards,
Boyan Dimitrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Sonia
Top achievements
Rank 1
answered on 23 Oct 2014, 10:07 AM
Hi Boyan,

I have just vote for it.
Thanks for the temporary solution.
Tags
ComboBox
Asked by
Sonia
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Sonia
Top achievements
Rank 1
Share this question
or