我正在尝试使用 jqgrid 形式实现 bootstrap select2,但似乎可以得到正确的结果。
在 jqgrid 声明的 colmodel 上我有:
{name: 'staff', index: 'staff', width: 31, formoptions: {elmprefix: '(*) '}, editable: true, editrules: {required: true}, edittype: 'select',
editoptions: {value: staff,
dataInit: function(element) {
$(element).width(260).select2();
}
}
},
选项在那里, Bootstrap 类被插入到元素中,
<select id="staff" class="select2-offscreen FormElement" role="select"
但我得到的只是选择的空白区域。
见下图。
有人可以告诉我为什么会发生这种情况,或者告诉我我做错了什么吗?
谢谢。
最佳答案
我不知道select2之前的插件。我尝试了一下,没有发现任何问题。我想您对宽度有问题只是因为在 $(element).width(260).select2();
中使用了太大的 width
函数参数。
演示:one没有 Bootstrap 和 another one包含 Bootstrap 3.0.0 可以正常工作。选择如下图所示
我在演示中使用
formatter: "select", edittype: "select",
editoptions: {
value: "FE:FedEx;TN:TNT;IN:Intim",
defaultValue: "Intime",
dataInit: function(element) {
$(element).width(122).select2({
// add "ui-widget" class to have the same font-family like in
// jQuery UI Theme
// add "ui-jqdialog" class to have font-size:11px like in other
// items of jqGrid form
dropdownCssClass: "ui-widget ui-jqdialog"
});
}
},
stype: "select",
searchoptions: {
value: "FE:FedEx;TN:TNT;IN:Intim",
defaultValue: "Intime",
dataInit: function(element) {
$(element).width(122).select2({
// add "ui-widget" class to have the same font-family like in
// jQuery UI Theme
// add "ui-jqdialog" class to have font-size:11px like in other
// items of jqGrid form
dropdownCssClass: "ui-widget ui-jqdialog"
});
}
}
并添加了以下 CSS 以提高可见性(根据我个人的口味)
.ui-jqdialog .select2-container .select2-choice {
height: auto;
padding-top: 1px;
padding-left: 0.2em;
padding-bottom: 2px;
line-height: 15px;
}
.ui-jqdialog .select2-container .select2-choice .select2-arrow b {
background-position: 0 -4px;
}
.ui-jqdialog.select2-drop { padding: 0px; }
.ui-jqdialog .select2-results .select2-result-label {
padding: 2px;
}
此外,我在使用 Bootstrap CSS 的演示中添加了更多 CSS:
.ui-jqgrid table {border-collapse: separate}
.ui-jqgrid .ui-pg-input, .ui-jqgrid .ui-pg-selbox {height: 17px}
.ui-jqgrid .ui-pg-table {padding-bottom: 0}
关于jquery - 将 bootstrap select2 与 JqGrid 表单一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395680/