如何在自动调整大小时设置日期搜索工具栏字段宽度
How to set date search toolbar field width on autoresize
我*正在寻找一种在自动调整大小时设置日期工具栏搜索字段宽度的方法。
我尝试了
中的代码
评论:
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
},
autoResizing: { minColWidth: 50 },
autoResizable: true,
width: 100,
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 },
{ name: "Second", width: 85 }
],
resizeStop: function (newWidth, iCol) {
var colModel = $(this).jqGrid("getGridParam", "colModel");
if ($("#gs_" + $.jgrid.jqID(colModel[iCol].name)).attr("type") === "date") {
$("#gs_IsActive").width(newWidth - 7); // - padding
}
},
jsonReader: {
id: "Id",
repeatitems: false
},
viewrecords: true
}).jqGrid("filterToolbar");
$(".ui-search-table input[type=date]").each(function() {
$(this).css("width", $(this).closest("th.ui-th-column").width() + "px");
});
css:
<div class="container">
<table id="categorysummary"></table>
</div>
见fiddlehttp://jsfiddle.net/10qwgejj/13/
双击活动列中的列分隔线后 header 搜索元素太大,列边框从搜索工具栏中消失。
要在自动调整大小时设置搜索字段宽度?
安德鲁斯
我实现了(参见 the commit)新回调 afterResizeDblClick
和新事件 jqGridAfterResizeDblClick,这使得解决方案变得非常简单。
它使用以下代码
var adjustSearchingDateField = function (cmName, newWidth) {
var $searchingField = $("#gs_" + $.jgrid.jqID(cmName));
if ($searchingField.attr("type") === "date") {
$searchingField.width(newWidth - 7); // - padding
}
};
...
resizeStop: function (newWidth, iCol) {
var colModel = $(this).jqGrid("getGridParam", "colModel");
adjustSearchingDateField(colModel[iCol].name, newWidth);
},
afterResizeDblClick: function (options) {
adjustSearchingDateField(options.cmName, options.cm.width);
},
...
我*正在寻找一种在自动调整大小时设置日期工具栏搜索字段宽度的方法。
我尝试了
中的代码评论:
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
},
autoResizing: { minColWidth: 50 },
autoResizable: true,
width: 100,
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 },
{ name: "Second", width: 85 }
],
resizeStop: function (newWidth, iCol) {
var colModel = $(this).jqGrid("getGridParam", "colModel");
if ($("#gs_" + $.jgrid.jqID(colModel[iCol].name)).attr("type") === "date") {
$("#gs_IsActive").width(newWidth - 7); // - padding
}
},
jsonReader: {
id: "Id",
repeatitems: false
},
viewrecords: true
}).jqGrid("filterToolbar");
$(".ui-search-table input[type=date]").each(function() {
$(this).css("width", $(this).closest("th.ui-th-column").width() + "px");
});
css:
<div class="container">
<table id="categorysummary"></table>
</div>
见fiddlehttp://jsfiddle.net/10qwgejj/13/
双击活动列中的列分隔线后 header 搜索元素太大,列边框从搜索工具栏中消失。
安德鲁斯
我实现了(参见 the commit)新回调 afterResizeDblClick
和新事件 jqGridAfterResizeDblClick,这使得解决方案变得非常简单。
它使用以下代码
var adjustSearchingDateField = function (cmName, newWidth) {
var $searchingField = $("#gs_" + $.jgrid.jqID(cmName));
if ($searchingField.attr("type") === "date") {
$searchingField.width(newWidth - 7); // - padding
}
};
...
resizeStop: function (newWidth, iCol) {
var colModel = $(this).jqGrid("getGridParam", "colModel");
adjustSearchingDateField(colModel[iCol].name, newWidth);
},
afterResizeDblClick: function (options) {
adjustSearchingDateField(options.cmName, options.cm.width);
},
...