selectedKeyNames returning id for rows with k-state-disabled

1 Answer 304 Views
Grid
luke
Top achievements
Rank 1
luke asked on 02 Apr 2022, 05:24 PM

I followed the direction in this forum post to disable the checkbox based on certain conditions:

https://www.telerik.com/forums/problem---select-all-checkbox-selects-disabled-row#login

Here's the runnable example:

https://dojo.telerik.com/alAtUWUb

However, when I click on the select-all checkbox, I realized selectedKeyNames() is selecting those that have been disabled.

You can verify that by adding "alert(this.selectedKeyNames().join(","));" in onChange function, and it will alert disabled checkbox id as well.

This is not desirable. How can I get the selectedKeyNames() for those checkboxes that are not selected?

1 Answer, 1 is accepted

Sort by
0
Georgi Denchev
Telerik team
answered on 06 Apr 2022, 11:17 AM

Hi, Luke,

Thank you for the provided Dojo.

You can remove the "Discontinued" ids from the internal selectedIds collection if there are any:

        function onChange(arg) {
          let dataSource = this.dataSource;
          $(".k-state-disabled").removeClass("k-state-selected");
          $(".k-state-disabled").find(".k-checkbox").prop("checked", false);
          
          let ids = this._selectedIds;
          for(let id in ids) {
            let item = dataSource.get(id);
            if(item.Discontinued) {
              delete ids[id];
            }
          }
          
          alert(this.selectedKeyNames().join(","));
        }

Updated Dojo:

https://dojo.telerik.com/@gdenchev/UPIPELOk 

Best Regards,
Georgi Denchev
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.

Tags
Grid
Asked by
luke
Top achievements
Rank 1
Answers by
Georgi Denchev
Telerik team
Share this question
or