免费的jqgrid与Bootstrap 3一起使用。
工具栏搜索包含html5日期字段。
日期字段的宽度大于列的宽度。
如果调整了列的大小,则日期字段的宽度会更大。
如何解决此问题,以便工具栏搜索中的日期字段宽度不比其列宽,并且在调整大小时不比列宽。
测试用例在http://jsfiddle.net/yt6L6p61/中
var serverResponse = {
"page": "1",
"records": "3",
"rows": [
{ "Id": "1", IsActive:'2015-01-09' },
{ "Id": "2", IsActive:'2015-01-05' },
{ "Id": "3", IsActive:'2015-01-21' }
]
},
initDateHtmlSearch = function (elem){
$(elem).attr("type", "date");
},
DateTemplate = {
sorttype: 'date',
formatter: 'date',
formatoptions: {
srcformat: "Y-m-d",
reformatAfterEdit: true
},
editoptions: {
maxlength: 10,
size: 10,
// dataInit: initDateEdit
},
editable: true,
searchoptions: {
sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'],
dataInit: initDateHtmlSearch,
size: 10,
attr: { size: 10 }
}
},
$grid = $("#categorysummary");
$grid.jqGrid({
url: "/echo/json/",
datatype: "json",
mtype: "POST",
postData: {
json: JSON.stringify(serverResponse)
},
colNames: ["Id", "Active", 'Second'],
colModel: [
{ name: 'Id', hidden: true },
{ name: 'IsActive', template: DateTemplate, width:90
},
{ name: 'Second', width:85
}
],
jsonReader: {
id: 'Id',
repeatitems: false
},
viewrecords: true
}).jqGrid("filterToolbar");
的HTML:
<div class="container">
<table id="categorysummary"></table>
</div>
请注意,测试用例中的第二列的行为符合预期:其宽度不比其列宽宽。
最佳答案
检查具有以下代码的修改后的演示http://jsfiddle.net/OlegKi/10qwgejj/4/
var serverResponse = {
"page": "1",
"records": "3",
"rows": [
{ "Id": "1", IsActive: "2015-01-09" },
{ "Id": "2", IsActive: "2015-01-05" },
{ "Id": "3", IsActive: "2015-01-21" }
]
},
dateTemplate = {
sorttype: "date",
formatter: "date",
formatoptions: {
srcformat: "Y-m-d",
reformatAfterEdit: true
},
editoptions: {
maxlength: 10,
size: 10
},
editable: true,
searchoptions: {
sopt: ["eq", "ne", "lt", "le", "gt", "ge"],
size: 10,
clearSearch: false,
attr: { size: 10, type: "date", style: "width:11em;" }
}
},
$grid = $("#categorysummary");
$grid.jqGrid({
url: "/echo/json/",
datatype: "json",
mtype: "POST",
postData: {
json: JSON.stringify(serverResponse)
},
colNames: ["Active", "Second"],
colModel: [
{ name: "IsActive", template: dateTemplate, width: 125 },
{ name: "Second", width: 85 }
],
jsonReader: {
id: "Id",
repeatitems: false
},
viewrecords: true
}).jqGrid("filterToolbar");
和其他CSS规则,用于解决由于使用Bootstrap CSS而导致的现有问题
.ui-search-table input[type=date] {
line-height: normal;
}
更新:可以在调整列大小后重新调整
input[type=date]
的大小。参见http://jsfiddle.net/OlegKi/10qwgejj/8/,它另外使用resizeStop: function (newWidth, iCol) {
var colModel = $(this).jqGrid("getGridParam", "colModel");
if (colModel[iCol].name === "IsActive") {
$("#gs_IsActive").width(newWidth - 7); // - padding
}
}