2012-07-25 43 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