I have a grid and I'm using PHP and JSON. I'm using ondblClickRow to do inline editing. The thing that I need is: when I double click in a field, I want the content of this field will be select. I'm sorry to ask about this, but I didn't find this... when I search it on Google I just find examples of select row and this issues.
Asked
Active
Viewed 2,652 times
1
-
What web browser you use? The order of `click` and `dblclick` events can be different in different web browsers. You can't prevent selection in case of `dblclick` if the `click` will be the first. You can only unselect the clicked line inside of `dblclick` event if it is really required. – Oleg Mar 13 '13 at 19:56
-
I'm using Firefox. Hummm I didn't know that! Thanks @Oleg. So I think I will have to change something to get a way to do this. Thanks again! :) – mailazs Mar 13 '13 at 20:14
4 Answers
2
I recommend you to look this answer and another one. Probably modification of the code from the last answer to the web browser which you use will get your the solution of your problem.
-
@mzs_newbie: Probably the second part of [another answer](http://stackoverflow.com/a/8334227/315935) could be helpful you too. It shows how to select text inside of cells. Using the same API you can unselect the text too. See [the answer](http://stackoverflow.com/a/3169849/315935), [this link](http://msdn.microsoft.com/en-us/library/ie/ff975178(v=vs.85).aspx) in addition. – Oleg Mar 14 '13 at 09:19
-
Once again... thanks @Oleg! You are always ready to help those who needs it! :D – mailazs Mar 14 '13 at 12:04
-
@mzs_newbie: If I understand you correctly you should select the text inside of [oneditfunc](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow) callback of inline editing. The callback will be called *after* all input controls are created. Alternatively you can do this inside of [dataInit](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:common_rules#editoptions). – Oleg Mar 14 '13 at 15:07
-
Almost work... but this disable the double click on a row to inline edit. What I would like to do is to double click then go to a inline edit and at the same time select the text of the field that I clicked. I would try to put this in `oneditfunc` but I'm already using this to implement the autocomplete :/ Can you help me? – mailazs Mar 14 '13 at 15:09
-
Hummm so do I have to implement this inside `dataInit`? Or which is the best option? Implement autocomplete inside `oneditfunc` or `dataInit`? – mailazs Mar 14 '13 at 15:11
-
1@mzs_newbie: If you need to do some additional actions inside of input control of some column (for example call `autocomplete`, select the text etc) then `dataInit` will be the best choice. If you need to do some actions after *all controls of the line will be created* then `oneditfunc` will be the best choice. – Oleg Mar 14 '13 at 15:15
-
@mzs_newbie: I don't understand what you mean under "disable the double click". – Oleg Mar 14 '13 at 15:16
-
Hummm now I got it! Ohh I'm sorry, I wrote this in the wrong way... What I mean is that when I double click just select the text and I can't edit the row... I'm sorry sometimes I don't know how to express myself :) – mailazs Mar 14 '13 at 15:16
-
And just one more thing... Can I do more than one "operation" inside `dataInit`? – mailazs Mar 14 '13 at 15:24
-
1@mzs_newbie: I though that you called `editRow` inside of `ondblClickRow`. I do this permanently in productive grids which I create. It allows to view grid like without any editing mode, but using double-click starts inline editing. I don't have problems with selection of the text. – Oleg Mar 14 '13 at 15:25
-
1@mzs_newbie: `dataInit` is just callback function. It can be so long as required. So you can do multiple operations of the editing controls (on `` for example). – Oleg Mar 14 '13 at 15:27
-
Humm so where do you call to select text? Omg! Thank you so much @Oleg! Now the things are clearer! Thanks again! Best regards :) – mailazs Mar 14 '13 at 15:28
-
@Oleg... could you help me with this question? [Question](http://stackoverflow.com/questions/15433876/autocomplete-datainit) – mailazs Mar 15 '13 at 18:09
-
@mzs_newbie: I am asked to help by answering on questions from many people. I have to make my main job too (which bring me and my family money :-)). I'll came to your question later after I'll finish some other things which I am doing currently. – Oleg Mar 15 '13 at 18:16
-
I'm sorry!!! Ok, no problem. I can wait the time you need! I just need your help :) Thank you so much and I'm sorry to bother you" :-) – mailazs Mar 15 '13 at 18:27
0
If you want a single cell to be focused after inline edit mode is enabled, try this:
ondblClickRow: function (rowId, rowIndex, columnIndex) {
var grid = $('#mygrid');
grid.editRow(rowId, true, function() {
var colModel = grid.getGridParam('colMode');
var colName = colModel[colIndex].name;
var input = $('#' + rowId + '_' + colName);
input.get(0).focus();
});
}
}
Found the code here: http://www.trirand.com/blog/?page_id=393/help/setting-focus-on-a-cell-after-entering-edit-mode/

Rob
- 5,578
- 3
- 23
- 28
-
Not a cell, but a row... I just want to put focus in that cell that I'm clicking and select the content... so do you think I have to implement cell edit too? Thanks – mailazs Mar 13 '13 at 19:15
-
Cell edit is for editing a single cell rather than a whole row. So you want the user to be able to double-click a row, have the row be in edit inline mode, but have the cell that the user double-clicked focus? I don't think that's possible, because the initial double-click happens on the row itself. After that, the editable elements are created. I think the user is just going to have to explicitly click the cell that they want to edit after the initial double-click. – Rob Mar 13 '13 at 19:27
-
Huuumm so so... I want to double click in a row, but when I click I want to select the content of the first field or the field that I'm with the cursor. So do you think this is possible @Rob? – mailazs Mar 13 '13 at 19:33
-
I still don't understand what it is you are trying to do. Are you trying to edit a single cell? Or are you only trying to select a single cell (not editing at all)? – Rob Mar 13 '13 at 19:48
-
I'm sorry if I wasn't so clear... I want to double click and edit a row. But when the row is enabled to edit I want that the content of a cell be selected without I'm doing this by myself. Did you understand me or I'm not so clear yet? – mailazs Mar 13 '13 at 19:54
-
Oook! Thanks @Rob! :D Just one more doubt... I'm using remote data. Is the same to implement with remote data? – mailazs Mar 13 '13 at 20:14
0
If you have specific columns in a grid when you click on it should select its contents, then in your colmodel add this code to each column:
{
name: 'TEXT_BOX',
index: 'TEXT_BOX',
label: 'Notes',
width: 100,
align: 'left',
sortable: false,
hidden: false,
dataEvents: [ { type: 'click', data: { i: 7 }, fn: function(e) { e.target.select(); } }]
}
dataEvents
will select the text in the input field when you click on it.
0
// Text will get Selected of cell when inline editing
$('#gridTableObj').jqGrid({
....
..
afterEditCell : function(rowid, cellname, value, iRow, iCol){
$('#'+rowid+'_'+cellname).select(); // with this the edited cell value will be selected.
}
...
..
});

Arun Pratap Singh
- 3,428
- 30
- 23