Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6561969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:39:12+00:00 2026-05-25T13:39:12+00:00

Last few days i was trying to get jqgrid with autocompletion fields to work,

  • 0

Last few days i was trying to get jqgrid with autocompletion fields to work, now i can get it to work with local data, but as soon as i trying to get data from my controller data didnt get parsed.

View code:

          { name: 'EanNummer', index: 'EanNummer', width: 65, sortable: true, editable: true, edittype: 'text', editoptions: {
              dataInit:
          function (elem) {
              $(elem).autocomplete({ minLength: 0, source: '@Url.Action("GetBrands")' })
              .data("autocomplete")._renderItem = function (ul, item) {
                  return $("<li></li>")
            .data("item.autocomplete", item)
            .append("<a>" + item.Id + ", " + item.Name + "</a>")
            .appendTo(ul);
              };
          } 
          }
          },

if instead of source: url i use source: [“c++”, “java”, “php”, “coldfusion”, “javascript”, “asp”, “ruby”] for example code works fine and shows up, so something must be wrong with my controller side code

Controller Code:

    public JsonResult GetBrands()
    {

        string vendorId = "";
        var username = "";
        var name = System.Web.HttpContext.Current.User.Identity.Name;
        var charArray = name.Split("\\".ToCharArray());
        username = charArray.Last();
        vendorId = service.GetVendorIdByUsername(username);

        List<String> list = new List<String>();
        var brands = service.getBrandsByVendor(vendorId);

        var s= (from brand in brands
                     select new
                     {
                         Id = brand.BrandId,
                         Name = brand.BrandName

                     }).ToList();

        return Json(s);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:39:13+00:00Added an answer on May 25, 2026 at 1:39 pm

    If you use item.Id and item.Name on the client side you should return not the List<String>. Instead of that you should returns the list of new {Id=brand.BrandId, Name=brand.BrandName}. You should just use LINQ instead of foreach:

    return Json ((from brand in brands
                  select new {
                      Id = brand.BrandId,
                      Name = brand.BrandName
                  }).ToList());
    

    UPDATED: I modified for you the demo from the answer and included jQuery UI Autocomplete support in two forms. The standard rendering:

    enter image description here

    and the custom rendering:

    enter image description here

    The Autocomplete functionality works in Advanced Searching dialog in the same way like in the Searching Toolbar:

    enter image description here

    You can download the demo from here.

    The server code of the standard autocomplete is

    public JsonResult GetTitleAutocomplete (string term) {
        var context = new HaackOverflowEntities();
        return Json ((from item in context.Questions
                      where item.Title.Contains (term)
                      select item.Title).ToList(),
                     JsonRequestBehavior.AllowGet);
    }
    

    It returns array of strings in JSON format. The list of Titles are filtered by term argument which will be initialized to the string typed in the input field.

    The server code of the custom autocomplete is

    public JsonResult GetIds (string term) {
        var context = new HaackOverflowEntities();
        return Json ((from item in context.Questions
                      where SqlFunctions.StringConvert((decimal ?)item.Id).Contains(term) 
                      select new {
                          value = item.Id,
                          //votes = item.Votes,
                          title = item.Title
                      }).ToList (),
                     JsonRequestBehavior.AllowGet);
    }
    

    It uses SqlFunctions.StringConvert to be able to use LIKE in comparing of the integers. Moreover it returns the list of objects having value the title property. If you would return objects having value the lable properties the values from the lable properties will be displayed in the Autocomplete context menu and the corresponding value property will be inserted in the input field. We use custom title property instead.

    The code of the client side is

    searchoptions: {
        dataInit: function (elem) {
            $(elem).autocomplete({ source: '<%= Url.Action("GetTitleAutocomplete") %>' });
        }
    }
    

    for the standard rendering and

    searchoptions: {
        sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'],
        dataInit: function (elem) {
            // it demonstrates custom item rendering
            $(elem).autocomplete({ source: '<%= Url.Action("GetIds") %>' })
                .data("autocomplete")._renderItem = function (ul, item) {
                    return $("<li></li>")
                        .data("item.autocomplete", item)
                        .append("<a><span style='display:inline-block;width:60px;'><b>" +
                            item.value + "</b></span>" + item.title + "</a>")
                        .appendTo(ul);
                };
        }
    }
    

    for the custom rendering.

    Additionally I use some CSS settings:

    .ui-autocomplete {
        /* for IE6 which not support max-height it can be width: 350px; */
        max-height: 300px;
        overflow-y: auto;
        /* prevent horizontal scrollbar */
        overflow-x: hidden;
        /* add padding to account for vertical scrollbar */
        padding-right: 20px;
    }
    /*.ui-autocomplete.ui-menu { opacity: 0.9; }*/
    .ui-autocomplete.ui-menu .ui-menu-item { font-size: 0.75em; }
    .ui-autocomplete.ui-menu a.ui-state-hover { border-color: Tomato }
    .ui-resizable-handle {
        z-index: inherit !important;
    }
    

    You can uncomment .ui-autocomplete.ui-menu { opacity: 0.9; } setting if you want to have some small
    opacity effect in the autocomplete context menu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the last few days I am trying to get data from my SQL
Been trying to get my head around while loops for the last few days
I've spent so much time the last few days trying to work out some
Last few days I'm trying to start with farseer library, however i just can't
I have spent the last few days trying to parse a SOAP response but
I've spent the last few days trying to remove memory leaks in my game,
I've been trying out Komodo IDE 6 for the last few days. I've always
I have been reading up and trying Git for the last few days and
Last few days I searched all over the internet to solve this problem but
For the last few days, I have been trying to use Python for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.