0

我正在使用 JQgrid,并且始终打开搜索对话框。我想让 Enter 键在按下时开始搜索。我尝试了其他一些解决方案,例如在搜索中使用 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();
4

1 回答 1

2

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

于 2012-04-04T14:08:30.170 回答