Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 想要使用jqgrid获取enter键来触发搜索吗_Javascript_Asp.net_Jqgrid - Fatal编程技术网

Javascript 想要使用jqgrid获取enter键来触发搜索吗

Javascript 想要使用jqgrid获取enter键来触发搜索吗,javascript,asp.net,jqgrid,Javascript,Asp.net,Jqgrid,我正在使用JQgrid,搜索对话框始终处于打开状态。我想让回车键在按下时启动搜索。我尝试了一些其他的解决方案,比如在搜索中使用onbeforeshowseach方法,但是它摆脱了我的始终打开的搜索框。有人能帮我弄清楚吗?以下是我的网格和搜索对话框代码: //Create the grid var grid = $("#list"), prmSearch = { multipleSearch: false, overlay: false }; var url = window.URLS.g

我正在使用JQgrid,搜索对话框始终处于打开状态。我想让回车键在按下时启动搜索。我尝试了一些其他的解决方案,比如在搜索中使用onbeforeshowseach方法,但是它摆脱了我的始终打开的搜索框。有人能帮我弄清楚吗?以下是我的网格和搜索对话框代码:

//Create the grid
var grid = $("#list"), prmSearch = { multipleSearch: false, overlay: false };
    var url = window.URLS.get('MySample');
    $("#list").jqGrid({
        url: url,
        datatype: 'json',
        mtype: 'POST',
        postData: {
            ignoreCurrentSelectionPage: function () { return ignoreCurrentSelectionPage; },
            groupNo: '<%= ViewBag.value1%>',
            groupType: '<%= ViewBag.value2%>'
        },
        colNames: ['Col1', 'Col2', 'Col3','Col4', 'Col5','Col6', 'Col7'],
        colModel: [
      { name: 'Col1', index: 'Col1', width: 300, align: 'center', hidden: true },
      { name: 'Col2', index: 'Col2', width: 250, align: 'left', search: true, searchoptions: { sopt: ['bw', 'ew','cn','eq', 'ne' ]} },
      { name: 'Col3', index: 'Col3', width: 240, align: 'left' , search: true, searchoptions: { sopt: ['bw', 'ew','cn','eq', 'ne'  ]}},
      { name: 'Col4', index: 'Col4', width: 100, align: 'center', search: false },
      { name: 'Col5', index: 'Col5', width: 100, align: 'center', search: false },
      { name: 'Col6', index: 'Col6', width: 100, align: 'center', search: false },
      { name: 'Col7', index: 'Col7', editable: true, edittype: 'checkbox', editoptions: { value: "yes:no" },search:false,
          formatter: "checkbox", formatoptions: { disabled: false }, align: 'center', width: 50
      },
      ],
        pager: jQuery('#pager'),
        rowNum: 15,
        rowList: [10, 15, 25, 50, 100, 500],
        sortname: 'Col2',
        sortorder: "asc",
        viewrecords: true,
        multiselect: false,
        multikey: "ctrlKey",
        caption: 'Sample',
        width: "100%",
        height: "100%",
        loadError: function (xhr, textStatus, errorThrown) {
        },
        gridComplete: function () {

            prmSearch = { multipleSearch: true, overlay: false };
            ignoreCurrentSelectionPage = true;
            $("#list").setSelection(selectedRowId, true);



            },

    }).navGrid('#pager', 
        { edit: false, add: false, del: false, search: true, refresh: true },
        {},  //  default settings for edit
        {}, //  default settings for add
        {},  // delete instead that del:false we need this
        {overlay:0}, // search options
        {}, /* view parameters*/
        prmSearch);
        // create the searching dialog 
        grid.searchGrid(prmSearch);
        // find the div which contain the searching dialog 
        //var searchDialog = $("#searchmodfbox_" + grid[0].id);
        var searchDialog = $("#searchmodfbox_" + grid[0].id);
        // make the searching dialog non-popup 
        searchDialog.css({ position: "relative", "z-index": "auto"});
        searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
        searchDialog.css({ position: "relative", "z-index": "auto", float: "left"});
        var gbox = $("#gbox_" + grid[0].id);
        gbox.before(searchDialog);
        gbox.css({ clear: "left"});
        //remove the empty span in the search dialog box.
        //we may need to re-add this is advanced searching is turned on
        $("#fbox_list").find('span:empty').parent().remove();

        //remove the empty span in the search dialog box.
        //we may need to re-add this is advanced searching is turned on
        $("#fbox_list").find('span:empty').parent().remove();
//创建网格
var grid=$(“#list”),prmSearch={multipleSearch:false,overlay:false};
var url=window.url.get('MySample');
$(“#列表”).jqGrid({
url:url,
数据类型:“json”,
mtype:“POST”,
postData:{
ignoreCurrentSelectionPage:函数(){return ignoreCurrentSelectionPage;},
组号:'',
组类型:“”
},
colname:['Col1','Col2','Col3','Col4','Col5','Col6','Col7',],
colModel:[
{name:'Col1',index:'Col1',width:300,align:'center',hidden:true},
{name:'Col2',index:'Col2',width:250,align:'left',search:true,searchoptions:{sopt:['bw','ew','cn','eq','ne']},
{name:'Col3',index:'Col3',width:240,align:'left',search:true,searchoptions:{sopt:['bw','ew','cn','eq','ne']},
{name:'Col4',index:'Col4',width:100,align:'center',search:false},
{name:'Col5',index:'Col5',width:100,align:'center',search:false},
{name:'Col6',index:'Col6',width:100,align:'center',search:false},
{name:'Col7',index:'Col7',edittype:'checkbox',editoptions:{value:'yes:no},search:false,
格式化程序:“复选框”,格式化选项:{disabled:false},对齐:'center',宽度:50
},
],
pager:jQuery(“#pager”),
rowNum:15,
行列表:[10,15,25,50,100,500],
sortname:'Col2',
分拣员:“asc”,
viewrecords:是的,
多选:错,
多键:“ctrlKey”,
标题:“样本”,
宽度:“100%”,
高度:“100%”,
loadError:函数(xhr、textStatus、errorshown){
},
gridComplete:函数(){
prmSearch={multipleSearch:true,overlay:false};
ignoreCurrentSelectionPage=true;
$(“#列表”).setSelection(selectedRowId,true);
},
}).navGrid(“#寻呼机”,
{编辑:false,添加:false,删除:false,搜索:true,刷新:true},
{},//编辑的默认设置
{},//添加的默认设置
{},//删除del:false,我们需要这个
{overlay:0},//搜索选项
{},/*视图参数*/
prmSearch);
//创建搜索对话框
搜索网格(prmSearch);
//查找包含搜索对话框的div
//var searchDialog=$(“#searchmodfbox”+网格[0].id);
var searchDialog=$(“#searchmodfbox”+网格[0].id);
//使搜索对话框不弹出
css({position:“relative”,“z-index:“auto”});
addClass(“UIJQGridUIWidgetUIWidgetContentUICornerAll”);
css({position:“relative”,“z-index:“auto”,float:“left”});
var gbox=$(“#gbox"+网格[0].id);
gbox.before(搜索对话框);
css({clear:“left”});
//删除“搜索”对话框中的空白范围。
//如果高级搜索已打开,我们可能需要重新添加
$(“#fbox_list”).find('span:empty').parent().remove();
//删除“搜索”对话框中的空白范围。
//如果高级搜索已打开,我们可能需要重新添加
$(“#fbox_list”).find('span:empty').parent().remove();

我回答了这个问题。相应的演示是。我想每次搜索都不容易找到答案,因为“搜索”、“对话”和“输入”这些词太常见了。

@JPiasente:我无法重现您描述的问题。你使用哪个版本的IE?你能准确地描述一下步骤吗。最后修改哪个字段很重要。控件将具有焦点。仅当焦点在数据字段(输入或选择)上时,才开始按Enter键搜索。这是你的问题,你应该阅读评论。在评论中,我描述了如果需要,如何将
keydown
事件绑定到所有控件。@JPiasente:我又尝试了一次,我在IE8中发布的引用,它可以正常工作。你写的是“描述”和“中心”。所以我想你的代码中有问题。我想您没有实现覆盖
onChange
的部分。@JPiasente:我在其中多次引用了上面如何覆盖内部方法
onChange
。您写道:“如果我在IE中将我的搜索字段更改为另一个字段(从描述更改为创建者),然后按enter键,它似乎不会启动搜索。”。我知道“描述”和“中心”在您的代码中,而不是在我的演示中。在我的演示中尝试同样的方法。您将看到它工作正常。因此,您应该将您的代码与我的演示代码进行比较,以找出差异。