Telerik MVC 网格自定义命令更新网格

发布于 2024-12-29 12:20:22 字数 1703 浏览 1 评论 0原文

如何使用自定义命令更新 Telerik 网格?例如,下面我有一个按钮,可以通过自定义命令按钮将行的姓氏更新为 Peters。调用了操作方法,但网格未更新。

@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"]);

行动方法:

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

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


    return View(new GridModel(persons));
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚我心虐我身 2025-01-05 12:20:22

添加到 ClientEvents 网格。

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

添加 javascript 以重建网格(如果操作是 Stuff):

@{ Html.Telerik().ScriptRegistrar().OnDocumentReady(@<text> 
function onComplete(e) {
   if (e.name == "Stuff") {
        var $grid = $("#Grid").data("tGrid");
        $grid.rebind();
   }
}
</text>); }

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>); }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文