2

How do you make a custom command update the telerik grid? For example below I have a button that updates the Last Name for the row to Peters via a custom command button. The action method is called, but the grid is not updated.

@Html.Telerik()
    .Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(o => o.FirstName);
        columns.Bound(o => o.LastName);
        columns.Bound(o => o.Phone);
        columns.Bound(o => o.State);
        columns.Command(commands => commands.Custom("Stuff")
                                        .Text("Change Name")
                                        .DataRouteValues(route => route.Add(o => o.LastName)
                                                            .RouteKey("lastName"))
                                        .Ajax(true)
                                        .Action("Stuff", "Home"));
    })
    .DataBinding(dataBinding =>
    {
        dataBinding.Server().Select("Index", "Home", new { ajax = ViewData["ajax"] });
        dataBinding.Ajax().Select("_Index", "Home").Enabled((bool)ViewData["ajax"]);
    })
    .Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
    .Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
    .Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
    .Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
    .Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
    .Footer((bool)ViewData["showFooter"]);

Action Method:

[GridAction]
public ActionResult Stuff(string lastName)
{
    IEnumerable<Person> persons = GetPersons();

    persons.First(p => p.LastName == lastName).LastName = "Peters";


    return View(new GridModel(persons));
}

1 Answer 1

2

Add to ClientEvents grid.

.ClientEvents(events => events.OnComplete("onComplete"))

Add javascript to rebuild the grid if action is Stuff:

@{ Html.Telerik().ScriptRegistrar().OnDocumentReady(@<text> 
function onComplete(e) {
   if (e.name == "Stuff") {
        var $grid = $("#Grid").data("tGrid");
        $grid.rebind();
   }
}
</text>); }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.