2011-09-30 4 views
0

내 JQgrid에는 대소 문자를 구분하는 ui atocomplete 열이 있습니다.Jqgrid 자동 완성 : 대소 문자 구분을 사용하지 않음

예를 들어, 그리드에 2 개의 항목이 있습니다. Ivan 및 ivan, "i"를 입력하면 자동 완성으로 ivan 만 반환됩니다. 소스의 내부에서 함수를 만들려고 시도했지만 AJAX 호출이 항상 객체 대신 Object 객체를 반환하기 때문에 실패했습니다. 어떤 아이디어? 자동 완성에 대한

코드 :

$(elem).autocomplete({ 
         delay: 0, 
         minLength: 0, 

         source: function (req, response) { 
          alert(req); 
          $.ajax({ 
           mtype: "post", 
           url: '@Url.Action("GetBrands")', 
           dataType: "json", 
           async: false, 
           cache: false, 
           data: { term: req }, 
           success: function (data) { 
            alert(data); 

            var re = $.ui.autocomplete.escapeRegex(req.term); 

            var matcher = new RegExp("^" + re, "i"); 

            response($.grep(data, function (item) { return matcher.test(item.value); })); 

           } 

          }); 

         }, 

컨트롤러 측 코드 : compering 때

public virtual JsonResult GetBrands(string term) 
    { 
     if (term == null) term = string.Empty; 

     var vendorId = _service.GetVendorIdByUsername(GetUserName()); 

     var brands = _service.GetBrandsByVendor(vendorId); 
     var brand = new BrandsViewModel(); 
     brand.BrandName = "Opret ny Brand..."; 
     brands.Add(brand); 

     foreach (var brandsViewModel in brands) 
     { 

      if (brandsViewModel.BrandName == "Intet") 
      { 
       brandsViewModel.BrandName = ""; 
      } 
     } 

     return Json((from item in brands 
        where item.BrandName.Contains(term) 
        select new 
           { 
            value = item.BrandName 
            //votes = item.Votes, 
           }).ToArray(), 
        JsonRequestBehavior.AllowGet); 
    } 

답변

1

한 경우에 모든 변환 :

public virtual JsonResult GetBrands(string term) 
    { 
     if (term == null) term = string.Empty; 
     term = term.ToLower(); 
     var vendorId = _service.GetVendorIdByUsername(GetUserName()); 

     var brands = _service.GetBrandsByVendor(vendorId); 
     var brand = new BrandsViewModel(); 
     brand.BrandName = "Opret ny Brand..."; 
     brands.Add(brand); 

     foreach (var brandsViewModel in brands) 
     { 

      if (brandsViewModel.BrandName == "Intet") 
      { 
       brandsViewModel.BrandName = ""; 
      } 
     } 

     return Json((from item in brands 
        where item.BrandName.ToLower().Contains(term) 
        select new 
           { 
            value = item.BrandName 
            //votes = item.Votes, 
           }).ToArray(), 
        JsonRequestBehavior.AllowGet); 
    } 
+0

잘 나는 그것에 대해 생각 만하고 싶어 클라이언트쪽에. 그러나 나는 이것을 붙잡는다. 감사 – Timsen

관련 문제