2010-07-23 4 views
0

는 내가있는 jqGrid있다 :특정 열의 jqGrid에서 검색 규칙을 사용자 정의하는 방법이 있습니까?

jQuery("#list").jqGrid({ 
      url : 'ajax/get', 
      datatype : 'json', 
      mtype : 'POST', 
      colNames : [ 
       'Date', 
       'ID' 
      ], 
      colModel : [{ 
        name : 'date', 
        index : 'date', 
        width : 60, 
       align : 'center', 
        searchoptions:{sopt:['gt', 'lt']} 
       },{ 
        name : 'id', 
        index : 'id', 
        width : 40, 
       align : 'center', 
        searchoptions:{sopt:['eq']} 
       }] 
    //....... 
     }); 

"날짜"열에서 "중 하나로, OData"옵션을 설정하는 방법이 있나요. 이제는 "더 큰" "적은"을 보여줍니다. 나는 "from"과 "to"이 필요하다. 그것은 작동하지 않습니다

colModel : [{ 
        name : 'date', 
        index : 'date', 
        width : 60, 
        align : 'center', 
        searchoptions:{sopt:['gt', 'lt'], odata:['from', 'to']} 
       } 

, 여전히 "큰"과 "덜"표시 :

나는이 시도. 시도이 : 그것은

$(document).ready(function(){ 
    $.jgrid.search = { 
    odata : ['equal','not equal', 'to', 'less or equal','from','greater or equal', 'begins with','does not begin with','is in','is not in','ends with','does not end with','contains','does not contain'] 
    }; 
    $.extend($.jgrid.search); 
}); 

는 대체 "더 큰"을 "로부터"와 "덜"모든 열에하지만 난 단지 "날짜"열에 필요 "방법"을 참조하십시오. 그것을 할 수있는 방법이 있습니까?

감사합니다.

답변

0

jqGrid에서 검색을 사용하려면 아마도 navGrid 기능을 호출하여 검색 버튼이있는 탐색기를 추가하십시오. navGrid은 6 번째 매개 변수로 $.jgrid.search (odata 포함)의 매개 변수를 덮어 쓰는 데 사용할 수있는 개체 (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:navigator#definition 참조)를 가지고 있습니다. 그래서 다음과 같은 것을 할 수 있습니다.

jQuery("#list").jqGrid('navGrid','#pager',{search:true},{},{},{}, 
       {odata:['equal','not equal', 'to', 'less or equal','from', 
         'greater or equal', 'begins with','does not begin with', 
         'is in','is not in','ends with','does not end with', 
         'contains','does not contain']}); 
+0

나를 위해 작동 할 수

// Events bubbling up the document may have been marked as prevented // by a handler lower down the tree; reflect the correct value. this.isDefaultPrevented = (src.defaultPrevented || src.getPreventDefault && src.getPreventDefault()) ? returnTrue : returnFalse; 

src.returnValue

을 제거하려면 다음 코드 (JQuery와 2.X 버전) =>를 교체합니다. 규칙은 변경되지 않습니다. 그럼에도 불구하고, 나는이 코드가 global $ .jqgrid.search를 대체 할 것이라고 생각하지만, "Date"컬럼에서만 필요하다. – andser

+0

코멘트를 작성하기 전에 코드를 테스트 해보십시오. http://www.ok-soft-gmbh.com/jqGrid/ClientsideEditing3.htm의 소스 코드를보고 두 번 클릭하여 데이터를 수정하고 "그룹"필드의 "이름"을 검색하십시오. 모든 것이 작동합니다. 원인의'navGrid' 매개 변수는'$ .jqgrid.search'에서 전역 설정을 덮어 쓰지 않습니다. – Oleg

1

비슷한 문제가있어서 jqGrid 소스 코드 중 일부를 편집하여 해결할 수 있습니다.

ops 배열에 연산자를 추가했습니다. (버전 4.4.0에서 6130 행이었습니다.)

ops : [ 
    {"name": "eq", "description": "equal", "operator":"="}, 
    {"name": "ne", "description": "not equal", "operator":"<>"}, 
    {"name": "lt", "description": "less", "operator":"<"}, 
    {"name": "le", "description": "less or equal","operator":"<="}, 
    {"name": "gt", "description": "greater", "operator":">"}, 
    {"name": "ge", "description": "greater or equal", "operator":">="}, 
    {"name": "bw", "description": "begins with", "operator":"LIKE"}, 
    {"name": "bn", "description": "does not begin with", "operator":"NOT LIKE"}, 
    {"name": "in", "description": "in", "operator":"IN"}, 
    {"name": "ni", "description": "not in", "operator":"NOT IN"}, 
    {"name": "ew", "description": "ends with", "operator":"LIKE"}, 
    {"name": "en", "description": "does not end with", "operator":"NOT LIKE"}, 
    {"name": "cn", "description": "contains", "operator":"LIKE"}, 
    {"name": "nc", "description": "does not contain", "operator":"NOT LIKE"}, 
    {"name": "nu", "description": "is null", "operator":"IS NULL"}, 
    {"name": "nn", "description": "is not null", "operator":"IS NOT NULL"}, 
    {"name": "to", "description": "to", "operator":"<"}, 
    {"name": "fr", "description": "from", "operator":">"} 
    ], 
numopts : 
    ['eq','ne','lt','le','gt','ge','nu','nn','in','ni'], 
stropts : 
    ['eq','ne','bw','bn','ew','en','cn','nc','nu','nn','in', 'ni','to','fr'], 

날짜 열 지정의 sopt 매개 변수에서 새 옵션을 사용하십시오. 검색 결과 구현에 따라이 연산자를 번역하려면 백엔드를 조정해야 할 수도 있습니다.

{name:'mydatefield', searchoptions: {sopt:['to', 'fr']}} 

희망 사항.

0
  1. 가있는 jqGrid 버전 4.5.4
  2. JQuery와 버전 1.9.0
  3. 크롬 버전 31.0.1650.48 m

(있는 jqGrid zip 파일에 포함) JQUERY 1.9/1.10에서 문제가있다 Chrome 31.x : event.returnValue는 더 이상 사용되지 않습니다. 대신 표준 event.preventDefault()를 사용하십시오.

http://bugs.jquery.com/ticket/14320 그것은 작동하지

관련 문제