This is a migrated thread and some comments may be shown as answers.

Re-binding grid after search?

4 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 17 Jan 2013, 09:14 PM

I'm just building my first kendo app - and my first mvc app, for that matter - and am stuck on one piece.  The page has a kendo grid that is populated using the View's model.  Above the grid is a search form, which triggers a "Search" controller action.  That action uses any criteria to get a new set of data and passes it back to the View, but the grid doesn't automatically re-bind to the data.  I'm not sure how to re-bind the grid, but if there is a way, where would I do it - in the View or the controller action? 

Here is my code - Grid:

@(Html.Kendo().Grid(Model)
      .Name("tblGrid")
      .Columns(columns =>
          {
              columns.Bound(w => w.Id).Hidden();
              columns.Bound(w => w.IncidentType).Width(160);
              columns.Bound(w => w.Location).Width(180);
              columns.Bound(w => w.IncidentDateTime).Width(120).Format("{0: MM/dd/yyyy H:mm tt}");
              columns.Bound(w => w.PostDateTime).Width(120).Format("{0: MM/dd/yyyy H:mm tt}");
          })           
      .DataSource(dataSource => dataSource
                                    .Server()
                                    .Model(model => model.Id(w => w.Id))
                                    .PageSize(15)
                                    .Create("Editing_Create", "Grid")                                       
      )
      .Events(events => events.Change("gridChange"))
      .Groupable()
      .Pageable()
      .Sortable()         
      .Selectable()         
      .Resizable(builder => builder.Columns(true))         
)

Search Controller:

[HttpPost]
public ActionResult Search([DataSourceRequest] DataSourceRequest request, string location, string reportNum, int? officerId, int? xref, int? days, int incidentTypeId)
{
    var summaries = new List<WatchSummaryInfo>();
    try
    {
        summaries = WatchSummaryBL.DoGetWatchListBySearch(SearchCriteriaHere).ToList();
    }
    catch (Exception ex)
    {               
        throw new Exception(ex.Message);
    }
 
    var filtered = new List<WatchSummaryViewModel>();
    try
    {
        foreach (var summary in summaries)
        {
            filtered.Add(new WatchSummaryViewModel{
                Id = summary.ID,
                IncidentDateTime = summary.WatchDateTime,
                IncidentType = summary.IncidentType,
                Location = summary.Location,
                PostDateTime = summary.PostDateTime                    
            });
        }
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }
                 
    return View("List", filtered);
}

I can verify by stepping through this that the collection I am passing back to the View has a much smaller subset (11) than the original ViewModel data, but the grid doesn't change.

What am I missing?

Thanks for the help!

Eddie

4 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 21 Jan 2013, 09:23 AM
Hello Eddie,

 
I could not reproduce the problem on our side. The grid is rebinding the data as expected. Could you attach a sample project so we are able to help you?

Kind regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Software
Top achievements
Rank 1
answered on 22 Jan 2013, 08:05 PM
Thanks for your reply.  I can put together a sample project, and am working on that now, but let me ask another question that may resolve this quicker...  I am using Ajax.BeginForm for this form, and I have not specified a method to run OnSuccess, or OnComplete.  Do I need to do something to re-bind the grid after the form is submitted.  Again, I can confirm that the Action is run, but I think I might be missing a piece of the puzzle that re-binds the grid.  So if I DO need to execute some Javascript OnSuccess or OnComplete, how do I re-bind the grid to the new collection in Javascript?

Here is my form code:
@using (Ajax.BeginForm("Search", "Home", new AjaxOptions { HttpMethod = "POST" })) {
     <table> ... FORM CODE HERE ... </table>
}
0
Dimiter Madjarov
Telerik team
answered on 24 Jan 2013, 11:37 AM
Hello Eddie,

You are using a server data source, which means that the grid data cannot be rebind without a page reload. If you want to use an Ajax form for data rebind, you should have an ajax data source for the grid too. Check out the Demos and the Documentation on the topic.

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Software
Top achievements
Rank 1
answered on 24 Jan 2013, 03:35 PM
Ok, I thought that might be the problem.  Thanks for pointing me in the right direction.
Tags
Grid
Asked by
Software
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Software
Top achievements
Rank 1
Share this question
or