Google Instant with AutoComplete and Grid

1 posts, 0 answers
  1. Jason Tully
    Jason Tully avatar
    4 posts
    Member since:
    Feb 2009

    Posted 25 Apr 2013 Link to this post

    Do you enjoy Google’s instant search feature?  If so, this is the tutorial for you.  Basically we want to create a widget that will update search results as you type in a text box. Google calls this “Instant”.  We can achieve this same functionality by combining the AutoComplete widget and the Grid widget.

    Setup the AutoComplete control.
                ds => ds.Read(
                    r => r.Action("BenefitSearch", "Home").Data("setTemplateListFilters")
                        ).ServerFiltering(true)).DataTextField("Description").HtmlAttributes(new { style="width:450px",placeHolder = "Search Existing Benefits"  })
    We need to set Suggest = false, otherwise the control will attempt to suggest a value within the search textbox.  The magic happens in our event handlers, “BenefitDataBound” and “OnOpen”.

    When the AutoComplete widget is databound, we simply want to extract the JSON data from the datasource and pass it off to a method that will create and bind a Grid.

    function BenefitDataBound(e, args) {
       function bindGrid(data) {
                   dataSource: {
                       data: data,
                       group: {
                   change: rowSelection,
                   selectable: "single",
                   height: 430,
                   navigatable: true,
                   scrollable: {
                       virtual: false
                   columns: [
    Or if you prefer to create everything using the MVC wrappers, you can do the following:

       .Columns(c =>
           c.Bound(x => x.Name);
           c.Bound(x => x.Category);
           c.Bound(x => x.Type);
           c.Bound(x => x.Version);
           c.Bound(x => x.LocalVersion).Title("Local Version");
       .DataSource(dataSource => dataSource
       .Scrollable(x => x.Height(200))
       .Sortable(sorting => sorting.SortMode(GridSortMode.SingleColumn))
    function BenefitDataBound(e, args) {
                    var grid = $("#ContentReport").data("kendoGrid");

    Lastly we need to prevent the AutoComplete widget from displaying any UI.  This can be handled by the OnOpen event handler.

    function OnOpen(e) {
    There you have it.  Enjoy!
Back to Top