7

I'm using inline editing with jqGrid, but when I select a cell, the cursor is set in the first column of the row, but I'd like to know if there is any way to edit the current cell I have clicked on, instead of the first row.

Thanks in advance.

Juan Francisco
  • 179
  • 3
  • 10
  • Similar question is in http://stackoverflow.com/questions/7219598/how-to-set-focus-to-cell-which-was-clicked-to-start-inline-edit-in-jqgrid which describes issues with Oleg demo – Andrus Aug 28 '11 at 09:29

1 Answers1

6

Very good point!

I personally prefer to use ondblClickRow event handler to start the editing mode. So you can use oneditfunc parameter of the editRow:

ondblClickRow: function(rowid,iRow,iCol,e) {
    grid.jqGrid('editRow',rowid,true,function(){
        $("input, select",e.target).focus();
    });
    return;
}

or just place the like of code which set the focus after the call of editRow:

ondblClickRow: function(rowid,iRow,iCol,e) {
    grid.jqGrid('editRow',rowid,true);
    $("input, select",e.target).focus();
    return;
}

See the corresponding demo here.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thanks for you help. And another question, every column in the data source must have a name, right? I have seen it in the example. – Juan Francisco Jul 03 '11 at 10:18
  • Yes, that's what I want to do, but it doesn't work, maybe I did something wrong, because it's still selecting the first column of the row. In my code, I have many jqgrids, and I should I need to use the name or the id of the grid to call the jquery function, right? – Juan Francisco Jul 04 '11 at 14:23
  • By the way, I'm creating my data on a controller in Json format, like this example: http://haacked.com/archive/2009/04/14/using-jquery-grid-with-asp.net-mvc.aspx – Juan Francisco Jul 04 '11 at 14:35
  • I have tested my code and it seems to work fine on chrome and firefox, but it doesn't with ie8. What could be the problem? – Juan Francisco Jul 04 '11 at 15:03
  • @Specter: If you has some problems with more as one grid you should verify that the grid data use different rowids. You can append your question with the code of the controller action which you use. – Oleg Jul 04 '11 at 15:15
  • @Specter: You wrote that you have more as one grid on the page. Where is the controller for the second grid? By the way, I recommend you too look at UPDATED part of [the answer](http://stackoverflow.com/questions/5500805/asp-net-mvc-2-0-implementation-of-searching-in-jqgrid/5501644#5501644) – Oleg Jul 04 '11 at 15:29
  • the rest of the grids doesn't have any data, by now. I'm testing for only one grid with data. – Juan Francisco Jul 04 '11 at 15:45
  • @Specter: We spend many time without any results. So is my demo http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridWithInlineEditingFocus.htm work on your computer in all web browsers? If it is work and your code not work, then your problem could be only in the code which you use. So to be able to help you I need have the code. It is easier you you open new question, include the client and the server codes and describe exactly what is not work correct. – Oleg Jul 04 '11 at 15:56
  • I have solved my problem. I hadn't declared the beforeSelectRow function and I had declared a function on the event onSelectRow, so that was the problem. Thanks for your patience. – Juan Francisco Jul 05 '11 at 14:34
  • @Specter: You are welcome! If the end is good, everything is good. – Oleg Jul 05 '11 at 14:47
  • This answer helped me on the spot. There is also a rather undocumented new focusField parameter that can be set on the editrow parameters that can be used that can be added to this answer. https://github.com/tonytomov/jqGrid/commit/e5a0baae4231df832ab92a9881ca9c027e6afdaf – elpddev May 07 '15 at 10:28
  • @elpd: I know about the `focusField` parameter. If you read any **old answer** on the stackoverflow that you should understand that it describes the state at the time or writing the answer (about 4 years ago). You can't expect that one update all previous answers with the new information based on every new release of jqGrid. Even the update of the documentation is a problem because not all users uses the latest version. Moreover jqGrid is **free** and you can't expect that somebody invest a lot of his time in editing information for other. Which fork and which version of jqGrid you use now? – Oleg May 07 '15 at 10:50
  • @Oleg Hi. First thanks for the answer. About the focusField, It was a suggestion, not expectation. I did not want to touch someone else correct answer so I just put it in the comment. – elpddev May 07 '15 at 14:32
  • @elpd: You are welcome! Starting with the end of December 2014 I started my fork of jqGrid: [**free jqGrid**](https://github.com/free-jqgrid/jqGrid). I posted some [wiki articles](https://github.com/free-jqgrid/jqGrid/wiki) and [readme](https://github.com/free-jqgrid/jqGrid/blob/master/README.md). The owner of old documentation is Tony. I plan to start soon new documentation about free jqGrid. Both old documentation and free jqGrid wiki are **opened for all for writing**. So you can modify the text or add new article. Best wishes! – Oleg May 07 '15 at 14:41