jqGrid的DatePicker的过滤没有击中回车键jqGrid的DatePicker的过滤没有击

2019-05-12 03:30发布

我建设我的第一个ASP.NET MVC 3应用程序和使用的jqGrid。 我的一个栏目,“味创建”,是一个日期栏,我想以过滤使用的DatePicker该列的网格。 以下是目前发生的情况:用户单击列标题过滤箱,显示日期选取器,然后将用户选择的年,月,日点击。 拾取器消失和离开日期,比方说,2009年3月28日,在文本框中。 实际得到的过滤工作,我要点击进入该框,然后按Enter键,这是一个有点恼人的用户。

有没有一种方法可以自动过滤器,当用户点击的那一天火?

(顺便说一句,我不知道有什么用“完成”按钮,是因为选择器消失时,我点击了一天。也许这就是我丢失的设置。)

任何人都需要这种功能,并解决它?

我试图做这样的事情:

dataInit: function (elem) {
  $(elem).datepicker({ changeYear: true, changeMonth: true, showButtonPanel: true,
    onSelect: function (dateText, inst) {
       $("#icecreamgrid")[0].trigger("reloadGrid");
    }
  })
}

因为我看到有人在一些网站的建议,但似乎并没有工作。

Answer 1:

你可以试试

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为出发thisdataInit 。 因此,人们不需要使用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");
            }
        }    
    });
}

免费的jqGrid与第二呼叫options的参数dataInit ,其中包含附加信息,如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");
            }
        }    
    });
}


文章来源: jqGrid DatePicker filtering without hitting Enter key
标签: jqgrid