Skip to content

DevExpress-Examples/asp-net-mvc-grid-focus-inserted-row

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET MVC - How to focus the newly inserted row

This example demonstrates how to use the grid's AddNewRowRouteValues property to focus the newly inserted row.

Overview

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:

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);
}

Files to Review

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

Use the grid's AddNewRowRouteValues property to focus the newly inserted row.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •