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

Disable Checkbox column based on bound data

2 Answers 2150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Iron
Mike asked on 13 Dec 2019, 07:59 PM

I have the following grid set.  Is there a way I can override the template or something else that will disable the checkbox based on a boolean from the data object?

    <kendo-grid selectable="multiple" height="600" auto-bind="false">
        <columns>
            <column selectable="true" width="30" locked="true" />
...
        </columns>
</kendo-grid>

2 Answers, 1 is accepted

Sort by
1
Accepted
Petar
Telerik team
answered on 18 Dec 2019, 09:26 AM

Hi Mike,

You cannot disable the checkboxes in the Grid directly by using the column template. Once the data in the Grid is bound, you can go through it and enable/disable the checkboxes based on the scenario in the application you are working on. Attached to my reply you will find a runnable project demonstrating how we can disable all checkboxes that are on rows with OrderID value bigger than 5. Here is the code that is executed on the dataBound event of the Grid:

    function onDataBound() {
        var grid = $("#grid").data("kendoGrid");
        var allRows = grid.items();
        $.each(allRows, function (index, value) {
            if (grid.dataItem(value).OrderID > 5) {
                 $(value).find(".k-checkbox").attr('disabled', true);
            }
        })
    }

I hope the above snippet demonstrates how you can achieve the desired functionality. Let me know if you need further assistance with the current case. 

Regards,
Petar
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Mike
Top achievements
Rank 1
Iron
answered on 19 Dec 2019, 04:24 PM
that worked, thank you.
Duhong
Top achievements
Rank 1
commented on 09 May 2024, 05:21 PM

After disabled, the checkboxes are checked when you check All.
Anton Mironov
Telerik team
commented on 14 May 2024, 08:04 AM

Hi Duhong,

Yes, you are totally correct - this is the expected behavior when the user checks the Select All option.

 

Kind Regards,
Anton Mironov

Mike
Top achievements
Rank 1
Iron
commented on 14 May 2024, 12:55 PM

@Duhong - you have to programatically account for whether the checkbox is enabled or not.  You cannot prevent the check all.  The solution prevents at least the direct selection but not the check all.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Iron
Answers by
Petar
Telerik team
Mike
Top achievements
Rank 1
Iron
Share this question
or