How to edit the selected cell on jqGrid
Asked Answered
B

1

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.

Brumby answered 30/6, 2011 at 14:49 Comment(1)
Similar question is in #7220098 which describes issues with Oleg demoTanney
C
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.

Convoke answered 30/6, 2011 at 16:37 Comment(14)
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.Brumby
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?Brumby
By the way, I'm creating my data on a controller in Json format, like this example: haacked.com/archive/2009/04/14/…Brumby
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?Brumby
@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.Convoke
@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 answerConvoke
the rest of the grids doesn't have any data, by now. I'm testing for only one grid with data.Brumby
@Specter: We spend many time without any results. So is my demo ok-soft-gmbh.com/jqGrid/… 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.Convoke
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.Brumby
@Specter: You are welcome! If the end is good, everything is good.Convoke
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. github.com/tonytomov/jqGrid/commit/…America
@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?Convoke
@Convoke 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.America
@elpd: You are welcome! Starting with the end of December 2014 I started my fork of jqGrid: free jqGrid. I posted some wiki articles and readme. 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!Convoke

© 2022 - 2024 — McMap. All rights reserved.