2011-03-17 92 views
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 
      ) ; 

} 

回答

1

你应该放在的sopt要在filterToolbar使用该选项的首位(为第一要素)。例如,对于所有选择元素(stype: 'select')和cnbw(其余为默认stype: 'text'),为en。如果没有搜索sopt选项在searchoptions的内部定义,您可以额外使用参数filterToolbar