JQGrid - 多选 [英] JQGrid - Multiselect
问题描述
JQGrid 中的多选仅允许多选或单选,并且移位功能不是我期望的移位选择所做的.我也不喜欢我们需要带有多选功能的组合框.
Multiselect in JQGrid only allows either multiple selection or single selections and the shift functionality isn't what I'd expect the shift select to do. I also don't like that we need comboboxes with multiselect.
我还可以为多选使用什么其他解决方案?
What other solution could I use for multiselect?
推荐答案
[2011 年 10 月] 更新为使用 4.0 API,更正了移位选择错误,简化了选择循环.在 4.2.0 中测试.
[Oct 2011] Updated to use 4.0 API, corrected shift-selection bugs, simplified selection loop. Tested in 4.2.0.
如果像我一样,您需要在 jqgrid 中进行适当的多选 - 其中 ctrl 一次选择一行,select 选择多行,既不清除选择,也不选择 1 行 - 您已经找到了.
If like me, you needed a proper multiselect in the jqgrid - where ctrl selects a single row at a time, select selects multiple rows and neither clear the selection and selects 1 row - You've found it.
第一件事:在网格定义中设置 multiselect: true
(我没有设置任何其他多选选项)
First things first: set multiselect: true
in the grid definition (I didn't set any other multiselect options)
下一步: 在 gridComplete: function () {}
中设置 grid.jqGrid('hideCol', 'cb');
- 这个如果您不想要复选框,请隐藏它们.
Next: In gridComplete: function () {}
set grid.jqGrid('hideCol', 'cb');
- this hides the checkboxes if you don't want them.
最后:主要部分
beforeSelectRow: function (rowid, e) {
if (!e.ctrlKey && !e.shiftKey) {
$("#grid").jqGrid('resetSelection');
}
else if (e.shiftKey) {
var initialRowSelect = $("#grid").jqGrid('getGridParam', 'selrow');
$("#grid").jqGrid('resetSelection');
var CurrentSelectIndex = $("#grid").jqGrid('getInd', rowid);
var InitialSelectIndex = $("#grid").jqGrid('getInd', initialRowSelect);
var startID = "";
var endID = "";
if (CurrentSelectIndex > InitialSelectIndex) {
startID = initialRowSelect;
endID = rowid;
}
else {
startID = rowid;
endID = initialRowSelect;
}
var shouldSelectRow = false;
$.each($("#grid").getDataIDs(), function(_, id){
if ((shouldSelectRow = id == startID || shouldSelectRow)){
$("#grid").jqGrid('setSelection', id, false);
}
return id != endID;
});
}
return true;
}
结局 - 希望有所帮助
这篇关于JQGrid - 多选的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!