【问题标题】:Telerik MVC Grid Ajax inline editing with automatic focusTelerik MVC Grid Ajax 内联编辑带自动对焦
【发布时间】:2012-07-26 03:14:31
【问题描述】:

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

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

有人知道如何将焦点自动设置到文本框吗? Telerik 是否有内置功能可以做到这一点?

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

谢谢。

【问题讨论】:

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


    【解决方案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

    【讨论】:

    • 很抱歉,我花了很长时间才接受这个答案,非常感谢,它工作得很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-25
    • 1970-01-01
    • 2011-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多