开发者

JqGrid Search Options: toolbarsearch vs standard search window

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',
                searchopt开发者_如何学编程ions: { 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜