Telerik MVC Grid Ajax内联编辑,具有自动对焦功能

时间:2012-07-25 15:46:56

标签: c# asp.net-mvc telerik-grid

在尝试了几个场景之后,我找不到如何将焦点自动设置到当前行中的第一个可编辑字段。

当您查看in this sample of Telerik时,当您点击编辑按钮时,您必须点击进入第一个文本框才能编辑内容。

enter image description here

有人知道如何自动将焦点设置到文本框吗? Telerik有内置功能吗?

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

谢谢。

1 个答案:

答案 0 :(得分: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