你可以试试
dataInit: function (elem) {
$(elem).datepicker({
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function() {
if (this.id.substr(0, 3) === "gs_") {
// in case of searching toolbar
setTimeout(function(){
myGrid[0].triggerToolbar();
}, 50);
} else {
// refresh the filter in case of
// searching dialog
$(this).trigger("change");
}
}
});
}
更新:从 4.3.3 版本开始,jqGrid 将网格的 DOM 初始化为 this 的 dataInit。因此不需要在上面的代码中使用myGrid 变量。而不是那个可以使用:
dataInit: function (elem) {
var self = this; // save the reference to the grid
$(elem).datepicker({
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function() {
if (this.id.substr(0, 3) === "gs_") {
// in case of searching toolbar
setTimeout(function () {
self.triggerToolbar();
}, 50);
} else {
// refresh the filter in case of
// searching dialog
$(this).trigger("change");
}
}
});
}
使用dataInit 的第二个options 参数进行免费jqGrid 调用,其中包含附加信息,例如mode 属性。 mode 属性的值是 "filter" 在过滤工具栏内部调用的情况下(和"search" 在搜索对话框的情况下)。因此可以使用以下代码
dataInit: function (elem, options) {
var self = this; // save the reference to the grid
$(elem).datepicker({
changeYear: true,
changeMonth: true,
showButtonPanel: true,
onSelect: function() {
if (options.mode === "filter") {
// in case of searching toolbar
setTimeout(function () {
self.triggerToolbar();
}, 0);
} else {
// refresh the filter in case of
// searching dialog
$(this).trigger("change");
}
}
});
}