我想使用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',$ myevent);但它不起作用,这里是错误(但如果它们是真正的原因我不是起诉):
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时,它可以正常工作,但不会保存等。
答案 0 :(得分: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;
}
}
});
});
}
});