本文介绍了jqGrid的搜索选项:toolbarsearch VS标准搜索窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想允许用户只使用一个SOPT设置过滤每一列。但对于更高级的搜索(高级用户),我想允许他们使用内置的搜索按钮,但我想覆盖在ODATA列出的各列的搜索选项。例如,我希望我的用户只有['情商']但我想电源用户能够从ODATA选择。但在搜索窗口中的搜索选项只能使用与列定义相关联的那些。

  oGridtxtsopt = ['CN'];
 oGriddtesopt = ['情商'];
 oGridnumsopt = ['情商'];
 oGridselsopt = ['情商'];
 oGridFile ='@ ViewBag.GridType';
 oGridSortColumn =名字;
 oGridColNames = ['名','姓','E-mail地址,日期,性别,国家名单,速度,年龄,电话号码',''];
 oGridColModel =
        [
            {名称:'名字',索引:'名字',宽度:110,searchoptions:{SOPT:['情商','体重']}},            {名称:'姓氏',索引:'姓氏',宽度:110,searchoptions:{SOPT:oGridtxtsopt}},            {名称:'EmailAddress的',索引:EmailAddress的',宽度:250,searchoptions:{SOPT:oGridtxtsopt},格式化:电子邮件},            {名称:'雇佣日期,索引:雇用日期,宽度:80,调整:中心,格式:'日期',formatoptions:{srcformat:'Y / M / D',newformat:'M / D / Y },
                sea​​rchoptions:{SOPT:oGriddtesopt,dataInit:amiDatePicker}},            {名称:'性别',索引:社会性别,宽度:55,调整:中心,STYPE:'选择',
                sea​​rchoptions:{dataUrl:'?@ Url.Action(amiLookup)' + $ .PARAM({查找:社会性别})}},            {名称:'国家',索引:'国家',宽度:110,对齐:中心,STYPE:'选择',
                sea​​rchoptions:{dataUrl:'?@ Url.Action(amiLookup)' + $ .PARAM({查找:'州'})}},            {名称:'率',索引:费率,宽度:45,调整:正确的,searchoptions:{SOPT:oGridnumsopt},格式:'数',formatoptions:{小数位数:2,后缀为:%} },            {名称:'年龄',索引:'年龄',宽度:30,调整:中心,searchoptions:{SOPT:oGridnumsopt},格式:'整'},            {名称:'电话',索引:'电话',宽度:95,调整:中心,searchoptions:{SOPT:oGridtxtsopt},格式:amiPhoneFormatter},            {名称:'动作',索引:'动作',宽度:40,调整:中心,排序:假的,搜索:假的,格式化:amiActionFormatter}
        ];        oGridSearch =endeavourSearch;
        oGridName =endeavourGrid;
        oGridPager =endeavourGridPager; $('#'+ oGridName).jqGrid
        ({            recordtext:oGridFile +发现 - {2},
            emptyrecords:否+ oGridFile +发现
            loadtext:搜索+ oGridFile +...
            pgtext:页面{0} {1},
            网址:'@ Url.Action(的GetData)',
            数据类型:JSON
            colNames:oGridColNames,
            colModel:oGridColModel,
            recreateFilter:真实,
            的rowNum:15,
            MTYPE:GET,
            rowList:[15,30,50,100],
            寻呼机:'#'+ oGridPager,
            sortname:oGridSortColumn,
            排序顺序:ASC
            高度:100%,
            viewrecords:真实,
            rownumbers:假的,
            GridView控件:真实,
            loadonce:假的,
            hidegrid:假的,
            clearfooter:真实,
            标题:oGridFile +列表,
            jsonReader:{repeatitems:假}        })        .filterToolbar(
            {
                stringResult:真的,searchOnEnter:真的,closeOnEscape:真
            })        .navGrid('#'+ oGridPager,
            {
                编辑:假的,加:假的,德尔:假的,刷新:假的,搜索:真实,
                sea​​rchtitle:搜索使用高级搜索选项,
                SEARCHTEXT:高级搜索
            },
            {} //编辑
            {} //添加
            {} //删除
            {
                closeOnEscape:真实,
                multipleSearch:真实,
                closeAfterSearch:真实,
                closeAfterReset:真实,
                标题:奋进高级搜索,
                查找:搜索,
                复位:取消,
                ODATA:['平等','不等于','少','小于或等于','更大','大于或等于','开始','不首先','是','是不是在','有','不是结束','包含','不包含']结束,
                groupOps:[{OP:和,文:所有的},{OP:OR,文:任何}],
                matchText:查找,
                rulesText:匹配            } //搜索
            {} //视图
            );}


解决方案

您应该放在首位(作为第一个元素) SOPT 的您想要的选项在 filterToolbar 使用。例如连接所有选择元素( STYPE:'选择')和 CN 体重的其余部分(默认 STYPE:文本)。你还可以使用 defaultSearch 的参数 filterToolbar 这将如果没有搜索 SOPT 选项被内部定义的 searchoptions

I want to allow users to filter each column using only one sopt setting. But for more advanced searching (for power users) I want to allow them to use the built in search button but I want to override the individual column search options for the ones listed in odata. For example I want my users to only have ['eq'] but I want power user to be able to choose from odata. But the search options in the search window only use the ones associated with the column definition.

 oGridtxtsopt = ['cn'];
 oGriddtesopt = ['eq'];
 oGridnumsopt = ['eq'];
 oGridselsopt = ['eq'];
 oGridFile = '@ViewBag.GridType';
 oGridSortColumn = "FirstName";
 oGridColNames = ['First Name', 'Last Name', 'E-mail Address', 'Date', 'Gender', 'State list', 'Rate', 'Age', 'Phone Number', ''];
 oGridColModel =
        [
            { name: 'FirstName', index: 'FirstName', width: 110, searchoptions: {sopt:['eq','bw']}},

            { name: 'LastName', index: 'LastName', width: 110, searchoptions: { sopt: oGridtxtsopt} },

            { name: 'EmailAddress', index: 'EmailAddress', width: 250, searchoptions: { sopt: oGridtxtsopt }, formatter: 'email' },

            { name: 'HireDate', index: 'HireDate', width: 80, align: "center", formatter: 'date', formatoptions: { srcformat: 'Y/m/d', newformat: 'm/d/Y' },
                searchoptions: { sopt: oGriddtesopt, dataInit: amiDatePicker} },

            { name: 'Gender', index: 'Gender', width: 55, align: "center", stype: 'select',
                searchoptions: { dataUrl: '@Url.Action("amiLookup")?' + $.param({ lookup: 'GENDER' })} },

            { name: 'State', index: 'State', width: 110, align: "center", stype: 'select',
                searchoptions: { dataUrl: '@Url.Action("amiLookup")?' + $.param({ lookup: 'STATES' })} },

            { name: 'Rate', index: 'Rate', width: 45, align: "right", searchoptions: { sopt: oGridnumsopt }, formatter: 'number', formatoptions: { decimalPlaces: 2, suffix: " %"} },

            { name: 'Age', index: 'Age', width: 30, align: "center", searchoptions: { sopt: oGridnumsopt }, formatter: 'integer' },

            { name: 'Phone', index: 'Phone', width: 95, align: "center", searchoptions: { sopt: oGridtxtsopt }, formatter: amiPhoneFormatter },

            { name: 'Action', index: 'Action', width: 40, align: "center", sortable: false, search: false, formatter: amiActionFormatter }
        ];

        oGridSearch = "endeavourSearch";
        oGridName = "endeavourGrid";
        oGridPager = "endeavourGridPager";

 $('#' + oGridName).jqGrid
        ({

            recordtext: oGridFile + " Found - {2}",
            emptyrecords: "No " + oGridFile + " Found",
            loadtext: "Searching " + oGridFile + "...",
            pgtext: "Page {0} of {1}",
            url: '@Url.Action("GetData")',
            datatype: "json",
            colNames: oGridColNames,
            colModel: oGridColModel,
            recreateFilter: true,
            rowNum: 15,
            mtype: "GET",
            rowList: [15, 30, 50, 100],
            pager: '#' + oGridPager,
            sortname: oGridSortColumn,
            sortorder: "asc",
            height: "100%",
            viewrecords: true,
            rownumbers: false,
            gridview: true,
            loadonce: false,
            hidegrid: false,
            clearfooter: true,
            caption: oGridFile + " List",
            jsonReader: { repeatitems: false }

        })

        .filterToolbar(
            {
                stringResult: true, searchOnEnter: true, closeOnEscape: true
            })



        .navGrid('#' + oGridPager,
            {
                edit: false, add: false, del: false, refresh: false, search: true,
                searchtitle: "Search using advanced search options",
                searchtext: "Advanced Search"
            },
            { }, // edit
            { }, // add
            { }, // delete
            {
                closeOnEscape: true,
                multipleSearch: true,
                closeAfterSearch: true,
                closeAfterReset: true,
                caption: "Endeavour Advanced Search",
                Find: "Search",
                Reset: "Cancel",
                odata: ['equal', 'not equal', 'less', 'less or equal', 'greater', 'greater or equal', 'begins with', 'does not begin with', 'is in', 'is not in', 'ends with', 'does not end with', 'contains', 'does not contain'],
                groupOps: [{ op: "AND", text: "all" }, { op: "OR", text: "any"}],
                matchText: "    Find",
                rulesText: " matches"

            }, // Search
            {} // view
            ) ;

}
解决方案

You should place on the first place (as the first element) of sopt the option which you want to use in the filterToolbar. For example en for all select elements (stype: 'select') and cn or bw for the rest (default stype: 'text'). You can additionally use defaultSearch parameter of filterToolbar which will be used if no search sopt option are defined inside of the searchoptions.

这篇关于jqGrid的搜索选项:toolbarsearch VS标准搜索窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:32