1

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.

SK.
  • 1,390
  • 2
  • 28
  • 59

1 Answers1

2

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;
}
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks a lot. I knew it will be YOU who can answer this and quickly. I tried everything except setSelection in ondblClickRow. To meet my requirement (i.e also to select a row by checking the checkbox) I added the below code and it is working. Could you please advice any better approach. if ( (e.target.tagName.toUpperCase() == "INPUT") && (clickedCellId.indexOf("jqg_grid1_") == 0) ) { return true; } else { return false; } – SK. Aug 25 '16 at 17:06
  • @Sudhir: You are welcome! I'm not sure what exactly you need to implement. What is `clickedCellId`? Do you use `multiselect: true`? Do you want allow to select by click on multiselect checkbox or on the cell with multiselect checkbox? In any way the usage of `.hasClass("cbox")` seems me better as `.indexOf("jqg_grid1_")`. – Oleg Aug 25 '16 at 17:35
  • var clickedCellId = e.target.id; yes, I use multiselect: true Yes, I want to click multiselect checkbox (which appears at the begining of each row) – SK. Aug 25 '16 at 17:49
  • @Sudhir: Sorry, but you don't answered on my question whether the `beforeSelectRow` should be modified to allow to select on click on the **checkbox** from multiselect column or on click on **the cell** which contains the checkbox. The checkbox is smaller as the corresponding cell. In any way every behavior can be easy implemented. It would be probably better if you post *new question* with the code which you use and which works not exactly like you want. If you would describe exactly what you need I could modify your existing code. – Oleg Aug 25 '16 at 19:37