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