Search code examples
javascriptjqueryjqgridjquery-eventsfree-jqgrid

How to allow go to specified page in free jqgrid pager


Free jqgrid has page number field. Entering page number to it and pressing enter should invoke specified table. This stopped to work at some time. Remote JSON data is used. Entering page number and pressing enter does nothing.

I added alert(key); to jqgrid source code as shown in code below before line

https://github.com/free-jqgrid/jqGrid/blob/master/js/jquery.jqgrid.src.js#L4045

If enter is pressed, alert box does not appear. If other keys are pressed, alert box appears.

How to fix this? How to find the reason why enter is ignored? Maybe some other method captures the enter key and cancels event so that it is not passed to this handler. How to find this out?

if (p.pginput === true) {
    $("input.ui-pg-input", pgcnt).bind("keypress.jqGrid", function (e) {
        var key = e.charCode || e.keyCode || 0, newPage = intNum($(this).val(), 1);
        alert(key); // ADDED
        if (key === 13) {
            if (!clearVals("user", newPage, intNum(p.rowNum, 10))) { return false; }
            $(this).val(newPage);
            p.page = ($(this).val() > 0) ? $(this).val() : p.page;
            populate.call(ts);
            return false;
        }
        return this;
    });
}

Update

Chrome developer tools shows the following listeners. How to find which blocks the enter key?

enter image description here


Solution

  • I suppose that the problem exist not in free jqGrid. I guess that some other handle of keydown which you registered returns false (or in some other way like e.preventDefault()), which prevent processing of other keydown and processing of <kbd>Enter</kbd> key. To be sure one has to debug all registered keydown and keydown handlers.

    UPDATED: I suppose that you move the pager input field inside of navigator bar (as I remember your old questions). As the result the Enter in the pager input will be replaced to the click.

    $focused = $(this).find(":focus");
    if ($focused.length > 0) {
        $focused.trigger("click");
        return false;
    }
    

    The problem is not exist in the standard navigator bar. It is exist only after your customization of the navigator bar. Nevertheless I posted today the changes which modifies the line $focused = $(this).find(":focus"); to

    $focused = $(this).find(".ui-pg-button").filter(":focus");
    

    It makes no effects in the standard navigator of the free jqGrid, but it can solve the problem which exists after your customization of the navigator bar.