Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7567643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:42:57+00:00 2026-05-30T14:42:57+00:00

Using jqGrid I want to open a cell-editor on double-click , so my code

  • 0

Using jqGrid I want to open a cell-editor on double-click, so my code includes this part:

  ondblClickRow: function(rowid, iRow, iCol, e)
  {
    jQuery('#jqGrid').setGridParam({cellEdit: true});
    jQuery('#jqGrid').editCell(iRow, iCol, true);
    jQuery('#jqGrid').setGridParam({cellEdit: false});
  }

which works fine, but I don’t know how to (auto-) close the cell-editor, when user click outside of the edit element, or press ESC, TAB, ENTER, etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:42:58+00:00Added an answer on May 30, 2026 at 2:42 pm

    The problem is that you try to implement cell editing on double-click which is not supported. Your current code don’t work because if the user press Tab, Enter or Esc key the nextCell, prevCell, saveCell or restoreCell will be really called, but the methods tests internally whether cellEdit parameter is true.

    To show how to fix the problem I created the demo which uses the following code:

    cellsubmit: 'clientArray',
    ondblClickRow: function (rowid, iRow, iCol) {
        var $this = $(this);
    
        $this.jqGrid('setGridParam', {cellEdit: true});
        $this.jqGrid('editCell', iRow, iCol, true);
        $this.jqGrid('setGridParam', {cellEdit: false});
    },
    afterEditCell: function (rowid, cellName, cellValue, iRow) {
        var cellDOM = this.rows[iRow], oldKeydown,
            $cellInput = $('input, select, textarea', cellDOM),
            events = $cellInput.data('events'),
            $this = $(this);
        if (events && events.keydown && events.keydown.length) {
            oldKeydown = events.keydown[0].handler;
            $cellInput.unbind('keydown', oldKeydown);
            $cellInput.bind('keydown', function (e) {
                $this.jqGrid('setGridParam', {cellEdit: true});
                oldKeydown.call(this, e);
                $this.jqGrid('setGridParam', {cellEdit: false});
            });
        }
    }
    

    UPDATED: If you want to discard or save the last editing changes if the user click on any other cell one should extend the code with the following:

    beforeSelectRow: function (rowid, e) {
        var $this = $(this),
            $td = $(e.target).closest('td'),
            $tr = $td.closest('tr'),
            iRow = $tr[0].rowIndex,
            iCol = $.jgrid.getCellIndex($td);
    
        if (typeof lastRowIndex !== "undefined" && typeof lastColIndex !== "undefined" &&
                (iRow !== lastRowIndex || iCol !== lastColIndex)) {
            $this.jqGrid('setGridParam', {cellEdit: true});
            $this.jqGrid('restoreCell', lastRowIndex, lastColIndex, true);
            $this.jqGrid('setGridParam', {cellEdit: false});
            $(this.rows[lastRowIndex].cells[lastColIndex])
                .removeClass("ui-state-highlight");
        }
        return true;
    }
    

    The new demo shows the results.

    UPDATED 2: Alternatively you can use focusout to discard or save the last editing changes. See one more demo which use the code:

    ondblClickRow: function (rowid, iRow, iCol) {
        var $this = $(this);
    
        $this.jqGrid('setGridParam', {cellEdit: true});
        $this.jqGrid('editCell', iRow, iCol, true);
        $this.jqGrid('setGridParam', {cellEdit: false});
    },
    afterEditCell: function (rowid, cellName, cellValue, iRow, iCol) {
        var cellDOM = this.rows[iRow].cells[iCol], oldKeydown,
            $cellInput = $('input, select, textarea', cellDOM),
            events = $cellInput.data('events'),
            $this = $(this);
        if (events && events.keydown && events.keydown.length) {
            oldKeydown = events.keydown[0].handler;
            $cellInput.unbind('keydown', oldKeydown);
            $cellInput.bind('keydown', function (e) {
                $this.jqGrid('setGridParam', {cellEdit: true});
                oldKeydown.call(this, e);
                $this.jqGrid('setGridParam', {cellEdit: false});
            }).bind('focusout', function (e) {
                $this.jqGrid('setGridParam', {cellEdit: true});
                $this.jqGrid('restoreCell', iRow, iCol, true);
                $this.jqGrid('setGridParam', {cellEdit: false});
                $(cellDOM).removeClass("ui-state-highlight");
            });
        }
    }
    

    UPDATED 3: Starting with jQuery 1.8 one should use $._data($cellInput[0], 'events'); instead of $cellInput.data('events') to get the list of all events of $cellInput.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble constructing a jqGrid TreeGrid using local data. This method works
I'm using jqgrid to display a list of sites and I want to do
I am using jqGrid to render some data. Now I want the ability to
I'm using the jQuery plugin that generates interactive tables called jqGrid . I want
hi i am using jqgrid and want to do something like if i set
I am using jqGrid and I don't want the grid to autoload. I only
I'm using jqGrid and adding my own onclick event to each cell of data
I'm using jqgrid 3.8.2, I'm trying to use below code to reload data from
i am using jqGrid treegrid and i want to format the back color of
OK, I am using jqgrid to only display a subset of information. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.