This example demonstrates how to use the grid's AddNewRowRouteValues property to focus the newly inserted row.
After the grid adds a new row to the data source, you can get the row's key value in an action specified by the grid's AddNewRowRouteValues property. To focus the newly inserted row, handle the grid's BeforeGetCallbackResult event and do the followng in the handler:
- Call the grid's FindVisibleIndexByKeyValue method to get the row's visible index.
- Assign that index to the grid's FocusedRowIndex property.
var grid = Html.DevExpress().GridView(settings => {
settings.Name = "GridView";
settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial" };
settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Home", Action = "AddNew" };
settings.KeyFieldName = "ID";
<!-- ... -->
settings.BeforeGetCallbackResult = (s, e) => {
var gridView = s as MVCxGridView;
gridView.FocusedRowIndex = gridView.FindVisibleIndexByKeyValue(ViewData["newKey"]);
};
});
public ActionResult AddNew(Entry e) {
ViewData["newKey"] = e.ID;
var model = GetData().ToList();
model.Add(e);
return PartialView("_GridViewPartial", model);
}
(you will be redirected to DevExpress.com to submit your response)