How to use Autocomplete with jqGrid library Lib.Web.MVC

200 Views Asked by At

I need an example to help me implement Autocomplete with jqGrid library Lib.Web.MVC.

The functionality is announced in this blog. A nice screenshot is provided but no sample code for these two:

  • JqGridColumnEditTypes.JQueryUIAutocomplete
  • JqGridColumnSearchTypes.JQueryUIAutocomplete

This code gives an error object referenced not found:

[Required]
[JqGridColumnSortable(true)]
[JqGridColumnSearchable(true, SearchType=JqGridColumnSearchTypes.JQueryUIAutocomplete)]
public string Place { set; get; }
1

There are 1 best solutions below

1
On BEST ANSWER

The mentioned blog post contains link to sample project.

In order for JqGridColumnSearchTypes.JQueryUIAutocomplete to work you need to provide controller and action name as parameters for the attribute, something like this:

[Required]
[JqGridColumnSortable(true)]
[JqGridColumnSearchable(true, "ActionName", "ControllerName", SearchType=JqGridColumnSearchTypes.JQueryUIAutocomplete)]
public string Place { set; get; }

The action needs to return data in jQuery UI autocomplete compatible format, so something like this:

public ActionResult Places(string term)
{
    return Json(
        _placesRepository
            .Find(String.Format("Name.StartsWith(\"{0}\")", term))
            .Select(p => p.Name).ToArray()
        , JsonRequestBehavior.AllowGet);
}

I hope this answers your question.