2
我想允許用戶只使用一個sopt設置來篩選每列。但對於更高級的搜索(對於高級用戶),我希望允許他們使用內置的搜索按鈕,但我想覆蓋odata中列出的各列搜索選項。例如,我希望我的用戶只有['eq'],但我希望高級用戶能夠從odata中進行選擇。但搜索窗口中的搜索選項僅使用與列定義關聯的搜索選項。JqGrid搜索選項:toolbarsearch vs標準搜索窗口
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
) ;
}