开发者

Jqgrid ui autocompletion : Disable Case sensitivity

开发者 https://www.devze.com 2023-04-09 19:50 出处:网络
In my JQgrid i have a ui atocomplete column which are Case sensitive. For example i have 2 Items in my grid: Ivan and ivan, if i type \"i\" autocomplete will return only ivan.

In my JQgrid i have a ui atocomplete column which are Case sensitive.

For example i have 2 Items in my grid: Ivan and ivan, if i type "i" autocomplete will return only ivan. I have tryed to make a function inside of source: but i failed since my ajax call always return object Object instead of an item. Any ideas?

Code for autocomplete:

$(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); }));

                              }

                          });

                      },

Controller side code:

 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);
    }


convert it all to one case when compering:

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

精彩评论

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