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屋!