剑道UI网格选择一行onload

问题描述 投票:0回答:1

我有一个用户名单。绑定到网格的用户列表。 我有一个当前登录的用户信息,位于 ViewData[用户]. 我想要的是,如果一个 网格中包含一个用户,这个用户在ViewData中,我想让这个用户在网格加载数据时就被选中。我怎样才能完成这个验证?我如何获得当前选中的行?

@(Html.Kendo().Grid(KendoGridAjaxBinding.Models.User)()  
 .Name("grid")  
 .DataSource(dataSource => dataSource   .Ajax()  
 .Read(read => read.Action("User_Read", "Home"))       
 .Columns(columns => {
    columns.Bound(user=> user.UserID);   
    columns.Bound(user=> user.UserName);   
    columns.Bound(user=> user.City);  
  ).Pageable().Sortable())  
kendo-grid
1个回答
1
投票

要预选一行,你可以尝试在网格中使用这段代码。

.RowAction(row => 
        {
            if (condition)
            {
                row.HtmlAttributes["class"] = "k-state-selected";
            }
        })

如果你正在编辑的话,你可以调用一个JavaScript函数来获取选中的行。

function editItem(e) {
            e.preventDefault();
            var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
            //the dataItem will be the user model
        }

或者看看这个帖子 剑道

© www.soinside.com 2019 - 2024. All rights reserved.