1

我想使用 jqGridRender(使用 javascript 的 jqGrid 的唯一 php 版本)实现一个多选功能。无论如何,我在实施它时遇到了麻烦。我找到了 javascript 的解决方案(你可以在预定义的函数中使用 javascript),这里是:http ://www.trirand.com/blog/?page_id=393/help/multiselect-with-shift-to-emulate -the-same-behaviour-as-in-the-file-explorer/#p9963我将此函数声明为 heredoc 字符串($myevent 变量),然后在 $gird->setGridEvent('onSelectRow', $我的事件);但它不起作用,这里是错误(但如果它们是真正的原因,我不会suer):

Notice: Undefined variable: gird in C:\xampp\htdocs\kmedia\grid.php on line 72

Fatal error: Call to a member function setGridEvent() on a non-object in C:\xampp\htdocs\kmedia\grid.php on line 72

我还想问一下,我如何制作 cellEdit 功能,将更改保存到变量中,因为当我将网格选项设置为 cellEdit 时,它可以工作,但不能保存等。

4

1 回答 1

1

您可以使用 Oleg 来自其他答案的好建议(我对其进行了一些修改):

$.extend($.fn.jqGrid, {
    bindKeys: function (settings) {
        var o = $.extend({
            onEnter: null,
            onSpace: null,
            onLeftKey: null,
            onRightKey: null,
            scrollingRows: true
        }, settings || {});
        return this.each(function () {
            var $t = this;
            if (!$('body').is('[role]')) { $('body').attr('role', 'application'); }
            $t.p.scrollrows = o.scrollingRows;
            $($t).keydown(function (event) {
                if (isInlineEdit()) {
                    return; // am if removed space etc does not work in inline edit
                }
                var target = $($t).find('tr[tabindex=0]')[0], id, r, mind,
                        expanded = $t.p.treeReader.expanded_field;
                if (!target && $t.p.selrow !== null) {
                    r = $("#" + $t.p.selrow);
                    if (r.length > 0) {
                        target = r[0];
                    }
                }
                //check for arrow keys
                if (target) {
                    mind = $t.p._index[target.id];
                    if (event.keyCode === 37 || event.keyCode === 38 || event.keyCode === 39 || event.keyCode === 40) {
                        // up key
                        if (event.keyCode === 38) {
                            r = target.previousSibling;
                            id = "";
                            if (r) {
                                if ($(r).is(":hidden")) {
                                    while (r) {
                                        r = r.previousSibling;
                                        if (!$(r).is(":hidden") && $(r).hasClass('jqgrow')) { id = r.id; break; }
                                    }
                                } else {
                                    id = r.id;
                                }
                            }
                            if ($.inArray(id, $t.p.selarrrow) === -1) {
                                if (!event.shiftKey) {// AM. added for shift+up arrow
                                    $($t).jqGrid('resetSelection');
                                    idsOfSelectedRows = []; // AM. Added
                                }
                                // todo: how to unselect row if shift is hold?
                                // this only selectcts row
                                $($t).jqGrid('setSelection', id);
                                saveWindowState();
                            } else {
                                $t.p.selrow = id;
                            }
                        }
                        //if key is down arrow
                        if (event.keyCode === 40) {
                            r = target.nextSibling;
                            id = "";
                            if (r) {
                                if ($(r).is(":hidden")) {
                                    while (r) {
                                        r = r.nextSibling;
                                        if (!$(r).is(":hidden") && $(r).hasClass('jqgrow')) { id = r.id; break; }
                                    }
                                } else {
                                    id = r.id;
                                }
                            }
                            if ($.inArray(id, $t.p.selarrrow) === -1) {
                                if (!event.shiftKey) {// AM. added for shift+up down arrow
                                    $($t).jqGrid('resetSelection'); // AM. added
                                    idsOfSelectedRows = [];
                                }
                                // todo: how to unselect row if shift is hold?
                                // this only selectcts row
                                $($t).jqGrid('setSelection', id);
                                saveWindowState();
                            } else {
                                $t.p.selrow = id;
                            }
                        }
                        // left
                        if (event.keyCode === 37) {
                            if ($t.p.treeGrid && $t.p.data[mind][expanded]) {
                                $(target).find("div.treeclick").trigger('click');
                            }
                            if ($.isFunction(o.onLeftKey)) {
                                o.onLeftKey.call($t, $t.p.selrow);
                            }
                        }
                        // right
                        if (event.keyCode === 39) {
                            if ($t.p.treeGrid && !$t.p.data[mind][expanded]) {
                                $(target).find("div.treeclick").trigger('click');
                            }
                            if ($.isFunction(o.onRightKey)) {
                                o.onRightKey.call($t, $t.p.selrow);
                            }
                        }
                        return false;
                    }
                    //check if enter was pressed on a grid or treegrid node
                    else if (event.keyCode === 13) {
                        if ($.isFunction(o.onEnter)) {
                            o.onEnter.call($t, $t.p.selrow);
                        }
                        return false;
                    } else if (event.keyCode === 32) {
                        if ($.isFunction(o.onSpace)) {
                            o.onSpace.call($t, $t.p.selrow);
                        }
                        return false;
                    }
                }
            });
        });
    }
});
于 2012-04-01T19:56:05.110 回答