Sudhir Sudhir - 3 months ago 36
jQuery Question

JQGrid: Select (that means highlight and check the checkbox) only on double click of a row, not on single click

I am trying select (i.e. highlight and check the checkbox) only on double click of a row, not on single click. But not getting getting a clue how to achieve this.

Can anyone please help me on this.

Answer

The solution consist from 3 steps:

  1. prevent default selection on click on the row
  2. selection of row on double-click
  3. preventing selection of the text in the cell on double-click

To prevent default selection one need include the following callback

beforeSelectRow: function () {
    return false; // prevent selection
}

To select on double-click one should call setSelection inside of ondblClickRow callback

ondblClickRow: function (rowid) {
    $(this).jqGrid("setSelection", rowid);
}

To prevent selection of the text in the cell on double-click one need to add CSS rule like the following:

.ui-jqgrid tr.jqgrow > td {
   -webkit-touch-callout: none;
   -webkit-user-select: none;
   -khtml-user-select: none;
   -moz-user-select: none;
   -ms-user-select: none;
   user-select: none;
}