2012-07-25 44 views
0

在尝试了几个方案后,我找不到如何自动将焦点设置到当前行中的第一个可编辑字段。Telerik MVC Grid带自动焦点的Ajax内联编辑

当你看看in this sample of Telerik,当你点击编辑按钮时,你必须点击第一个文本框来编辑内容。

enter image description here

任何人都知道如何自动将焦点设置到文本框? Telerik是否有内置的功能?

注意: 如果你去this sample;一个新的KendoUI,这正是我想要的行为。

谢谢。

回答

1

您应该可以挂钩OnEdit客户端事件并提供自己的函数来聚焦文本字段。您可能需要使用jQuery选择器来查找适合您需求的内容。

@(Html.Telerik().Grid(Model) 
    .Name("Grid") 
    .ClientEvents(events => events.OnEdit("Grid_onEdit"))) 

<script type="text/javascript"> 
    function Grid_onEdit(e) 
    { // focus the first grid element, or the first form element with a validation error 
     $("#Grid").find(":input:enabled:visible:first:not(:input[type=submit])").focus(); 
     $("#Grid").find(".input-validation-error").first().focus(); 
    } 
</script> 

更多关于客户端事件here

+0

很抱歉的很长一段时间我把接受这个答案,非常感谢你,它完美的作品。 – Samuel 2013-01-30 16:32:29