0

I've a question related to jqgrid v4.15.4. I have used beforeSubmitCell event to return new array that will be posted to the server. Also I've kept options cellEdit: true , cellsubmit: 'remote'. By default, if a jqGrid cell is editable, single click on that cell changes it to edit mode.Which I know can be done with ondblClickRow. But how can I call beforeSubmitCell event inside ondblClickRow event function.

for references, I've read : jQGrid Cell Editing on double click of row

Let me know if more info required?

Chandan
  • 217
  • 1
  • 3
  • 17
  • Did you read my answer? I didn't get any feedback on my answer during 20 days. – Oleg Jan 22 '19 at 19:32
  • Hello Oleg, Sorry for the delay response, I have initially checked your suggestion but wanted to test more with different cell type(text, dropdown, date), so not able to share my views. But Now I did in below answer. Please check. – Chandan Mar 04 '19 at 11:54
  • Sorry, but I don't understand what you mean with "But Now I did in below answer. Please check." Where you posted some additional information? Typically you should click "edit" link below the text of you question to edit the text. You can append the text with "UPDATED: ..." and then post new comment to inform me about changes in the text. – Oleg Mar 04 '19 at 11:59

1 Answers1

1

If I correctly understand your problem, the you should don't use the option cellEdit: true (but still use cellsubmit: 'remote') and to set cellEdit: true dynamically before calling cell editing methods (editCell, restoreCell, saveCell, prevCell or nextCell). Additionally you will have to duplicate the keyboard operations (see the lines of free jqGrid code). The resulting code could look like the code below:

ondblClickRow: function (rowid, iRow, iCol, e) {
    var $self = $(this), p = $self.jqGrid("getGridParam");
    p.cellEdit = true;
    $self.jqGrid("editCell", iRow, iCol, true);
    p.cellEdit = false;
},
afterEditCell: function (rowid, cmName, cellValue, iRow, iCol) {
    var getTdByColumnIndex = function (tr, iCol) {
            var $t = this, frozenRows = $t.grid.fbRows;

            tr = frozenRows != null && frozenRows[0].cells.length > iCol ?
                    frozenRows[tr.rowIndex] : tr;
            return tr != null && tr.cells != null ? $(tr.cells[iCol]) : $();
        },
        $td = getTdByColumnIndex.call(this, this.rows[iRow], iCol),
        $self = $(this),
        $t = this,
        p = $self.jqGrid("getGridParam");

    $("input, select, textarea", $td).on("keydown", function (e) {
        if (e.keyCode === 27) { //ESC
            p.cellEdit = true;
            $self.jqGrid("restoreCell", iRow, iCol);
            p.cellEdit = false;
        } else if (e.keyCode === 13 && !e.shiftKey) { //Enter
            p.cellEdit = true;
            $self.jqGrid("saveCell", iRow, iCol);
            p.cellEdit = false;
            return false;
        } else if (e.keyCode === 9) {
            if (!$t.grid.hDiv.loading) {
                p.cellEdit = true;
                if (e.shiftKey) {
                    $self.jqGrid("prevCell", iRow, iCol); //Shift TAb
                } else {
                    $self.jqGrid("nextCell", iRow, iCol); //Tab
                }
                p.cellEdit = false;
            } else {
                return false;
            }
        }
        e.stopPropagation();
    });
}

See https://jsfiddle.net/OlegKi/Lm7akxz2/

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Hi @Oleg, I have implemented the above code as you suggested and it worked fine with one issue which comes when the debugger(**F10**) pass the line **$self.jqGrid("saveCell", iRow, iCol);** . It says URL not set. What could be the possible reason for this? – Chandan Mar 04 '19 at 11:37
  • @Chandan: You don't posted the code which you use. Thus it's difficult for me to answer on your question. I can only guess. If you use `cellsubmit: "remote"` then you should specify `cellurl` to which the modified cell will be posted. Do you specified `cellurl`? – Oleg Mar 04 '19 at 11:43
  • I am trying to create a working demo from my project code. But until that will get completed, I can work with your suggestions. Meanwhile, I haven't specified cellurl. After your answer, I removed static cellurl from the grid. A small doubt here: Could it be possible to do that without passing cellurl? – Chandan Mar 04 '19 at 14:06
  • Also, Could you please provide some insights on this question? : https://stackoverflow.com/q/54314494/5822867 – Chandan Mar 04 '19 at 14:08
  • 1
    @Chandan: If you use the option `cellsubmit: "remote"` then you want that jqGrid post the modified data to the server instead of only saving the changes of cell editing locally. Thus you have to specify `cellurl` always if you use the option `cellsubmit: "remote"`. – Oleg Mar 04 '19 at 14:11
  • @Chandan: About your old question: I'm not sure that I understand the problem correctly. In any way if you need to clear selection over all pages (not only on the current page) then you can just set `selarrrow` parameter to `[]`. The corresponding code could be `var p = $("#list").jqGrid("getGridParam"); p.selarrrow = [];` – Oleg Mar 04 '19 at 14:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/189400/discussion-between-chandan-and-oleg). – Chandan Mar 04 '19 at 14:22
  • 1
    @Chandan: You can set `cellurl` value dynamically with the code like `var p = $("#list").jqGrid("getGridParam"); p.cellurl= "newUrl";` – Oleg Mar 04 '19 at 16:47
  • 1
    @Chandan: Alternatively you can define `cellurl` parameter as callback function `cellurl: function (currentCellurl, iRow, iCol, rowid, value, name) { return "dynamicUrl"; }`. I see that the current code use `currentCellurl` as the first parameter. I'll remove it in the next version of free jqGrid. The prototype of callback function will be fixed to `cellurl: function (iRow, iCol, rowid, value, name) { return "dynamicUrl"; }` – Oleg Mar 04 '19 at 16:54