Grid DropdownList AutoComplete

2 posts, 0 answers
  1. Informed Sources
    Informed Sources avatar
    18 posts
    Member since:
    Jan 2009

    Posted 02 Dec 2014 Link to this post

    Hi,

    I have a grid in which I have bound the DropDownLists to data, but on one of the list, the data is a very large list of products. I don't want to load the entire list, I want to have the user type in 3 letters, then automatically load the dropdownlist and allow selection. As the user types in more, the DropDownList will have fewer products to choose between. I want to save the productID, but display Category -> Product Name. 

    Is this possible?
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2203 posts

    Posted 04 Dec 2014 Link to this post

    Hi Adam,

    You can use the ComboBox widget with "ServerFiltering" option enabled - please check the example below:

    Additionally you can restrict the response from the server to only return the top 10 records (for example) from the filter query:

    public JsonResult GetProducts(string text)
    {
        var northwind = new SampleEntities();
     
     
        var products = northwind.Products.Select(product => new ProductViewModel
        {
            ProductID = product.ProductID,
            ProductName = product.ProductName,
            UnitPrice = product.UnitPrice ?? 0,
            UnitsInStock = product.UnitsInStock ?? 0,
            UnitsOnOrder = product.UnitsOnOrder ?? 0,
            Discontinued = product.Discontinued
        });
     
        if (!string.IsNullOrEmpty(text))
        {
            products = products.Where(p => p.ProductName.Contains(text));
        }
     
        products = products.Take(5);
     
        return Json(products, JsonRequestBehavior.AllowGet);
    }

    Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top