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

Conditionally Disable ".Select()" Checkbox for a Row

1 Answer 1113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
B
Top achievements
Rank 1
B asked on 25 Oct 2018, 08:31 PM

I want to be able to conditionally disable selection of a row based on another column on that row.  For example, I don't want to allow the user to select a row if a certain column is null.

I know how to conditionally set row and column attributes on data bound so think it's probably here but not sure what's next

function dataBound(e) {
    var rows = e.sender.tbody.children();
 
    for (var j = 0; j < rows.length; j++) {
        var row = $(rows[j]);
        var dataItem = e.sender.dataItem(row);
 
        // Disable the checkbox if the location isn't set
        if (dataItem.get("Location") === "") {
            row.css('background-color', '#FFFFCF');
            // What goes here?
        }
    }
 
    items = null;
}

 

I also tried to do this on the change event, which kind of work, but the selected IDs (selectedKeyNames) were still being set when the select all checkbox was clicked.

function onChange(e) {
 
    var i = e.sender.select();
    var grid = e.sender;
 
    i.each(function (i, e) {
        var dataItem = grid.dataItem(e);
        if (dataItem.get("Location") !== "") {
            $(e).removeClass("k-state-selected");
        }
    });
 
    items = this.selectedKeyNames();
 
}

 

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 29 Oct 2018, 02:46 PM
Hi,

There is no built-in functionality that will prevent the selection of particular rows and as you have found out, removing the class names from the TR element will not remove the id of the row from the selectedKeyNames collection. As a workaround I could suggest using custom function that will retrieve the selected keys after removing the "k-state-selected" class from the rows. In the following dojo example you will find cusom selectedKeyNames function:
Hope this helps.


Regards,
Konstantin Dikov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
B
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or