Telerik radgrid and GridClientSelectColumn how to use “click” instead of “ctrl click”)

multi-selectteleriktelerik-grid

I have a telerik radgrid and have added a GridClientSelectColumn to allow users to select single or multiple rows however the default is ctrl click to select multiple.

I want the following functionality without having to override this with my own javascript.

  • User clicks row and checkbox is checked
  • User clicks on checked row and checkbox is unchecked
  • User clicks row and then another row. both checkboxes are checked.
  • User does not have to use "ctrl click"

Is there an easy way to do this?

Best Answer

I managed this with help from the telerik forum.

Forum post

Add the following code to the RadCodeBlock

var originalClickedRowState = null;
var clickedRow = null;

function rgGrid_OnRowClick(sender, args) {
    clickedRow = args.get_gridDataItem();
    originalClickedRowState = args.get_gridDataItem().get_selected();
}

function rgGrid_OnRowDeselecting(sender, args) {
    if (clickedRow != null && clickedRow != args.get_gridDataItem()) {
            args.set_cancel(true);
    }
}

function rgGrid_OnRowSelecting(sender, args) {
    if (clickedRow == args.get_gridDataItem() && originalClickedRowState) {
        args.set_cancel(true);
        originalClickedRowState = null;
        clickedRow = null;
    }
}

function rgGrid_OnRowSelected(sender, args) {
    originalClickedRowState = null;
    clickedRow = null;
}

A gotcha is that you need to wire up the OnRowCreating and OnRowCreated events in the grids ClientSettings.ClientEvents

function OnRowCreating(sender, args) {}
function OnRowCreated(sender, args) {}
Related Topic