1

I'd like to implement a multiselect function using jqGridRender (the php only version of jqGrid that uses javascript). Anyways i'm having troubles implementing it. I've found solution for javascript (and you can use javascript in predefinded function), which is here: http://www.trirand.com/blog/?page_id=393/help/multiselect-with-shift-to-emulate-the-same-behaviour-as-in-the-file-explorer/#p9963 I'm declaring this function as heredoc string ($myevent variable), and then call it under $gird->setGridEvent('onSelectRow', $myevent); but it doesn't work, here are the errors (but i'm not suer if they are the real cause):

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

I'd also like to ask, how do i make cellEdit function, save the changes into variable, since when i'm setting grid options to cellEdit it works, but doesn't save etc.

Malyo
  • 1,990
  • 7
  • 28
  • 51
  • `$gird` is not an object. You need to initialize it first. – slash197 Mar 26 '12 at 08:00
  • Oh ye i have fixed the typo, anyways it doesn't work, there are no erros tho – Malyo Mar 26 '12 at 08:08
  • 1
    @Malyo: Related question is in http://stackoverflow.com/questions/10007453/how-to-de-select-selected-row-if-shiftup-arrow-key-is-pressed-in-jqgrid This contains code which allows de-select also. – Andrus Apr 04 '12 at 08:29

1 Answers1

1

You can use Oleg great suggestion from other answer (I modified it a bit):

$.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;
                    }
                }
            });
        });
    }
});
Andrus
  • 26,339
  • 60
  • 204
  • 378