Telerik mvc网格标签顺序问题

时间:2012-12-03 10:25:57

标签: asp.net-mvc model-view-controller telerik telerik-grid kendo-ui

我正在使用MVC 3.0应用程序。在我的项目中,我使用Telerk mvc grid进行数据列表。我将网格编辑模型设为“InCell”,并在我的问答区域提供了键盘导航。每个问题将有2个答案选项,如“事实”和“操作”,并将是数字值。为此,我使用了“整数”编辑器模板。我的要求是当用户从“Facts”整数教科书中按Tab键时,焦点会将其移动到“Actions”整数文本框,如果用户从“Actions”按下Tab,它将移动到下一行“Facts”文本框。但目前键盘导航遍历网格中的所有单元格。 “事实”和“行动”之间的列很少。我的网格列表代码看起来像。

@(Html.Telerik().Grid<AnswerQuestionVM>()
    .Name("GridQuestions")
    .DataKeys(keys =>
    {
        keys.Add(p => p.QuestionID);
    })
    .Columns(columns =>
    {

        columns.Bound(p => p.QuestionNumber).Format("{0:0.00}").HtmlAttributes(new { style = "text-align:center;" }).Title("#").Width("5%").ReadOnly();

        columns.Bound(p => p.QuestionName).Title("Question Name").Width("43%").ReadOnly();

        columns.Bound(p => p.Facts).Width("8%");

        columns.Template(@<text></text>).ClientTemplate("<img src='" + @Url.Content("~/images/help.gif") + "' name='help' alt='help' title='<#=FactOptions#>' />");

        columns.Bound(p => p.Actions).Width("8%");

        columns.Template(@<text></text>).Width("2%").ClientTemplate("<img src='" + @Url.Content("~/images/help.gif") + "' name='help' alt='help' title='<#=ActionOptions#>' />");

        columns.Template(@<text></text>).Title("Skip").Width("3%").ClientTemplate(
        "<# if(Skip==false) {#>" +
        "<input type='checkbox' style='cursor:pointer;' class='skipClass' />" +
                 "<#} else{#>" +
        "<input type='checkbox' style='cursor:pointer;' class='skipClass' checked='checked' />" +
        "<# } #>"
        );

        columns.Bound(p => p.Note).Title("Note").Width("26%");

    })
         .Editable(editing => editing.Mode(Telerik.Web.Mvc.UI.GridEditMode.InCell))
         .KeyboardNavigation( navigation => navigation.EditOnTab(true))
         .ClientEvents(e => e.OnSave("OnSave"))
         .DataBinding(dataBinding =>
         {
            dataBinding.Ajax().Select("GetQuestion", "AnswerQuestion", new { Area = "question",  ajax = true }).Enabled(true);
         })
                                                                                              .Scrollable(scrolling => scrolling.Enabled(false))
                                                                                             .Sortable(sorting => sorting.Enabled(true))
                                                                                             .Pageable(paging => paging.Enabled(true))
                                                                                             .Filterable(filtering => filtering.Enabled(true))
                                                                                             .Groupable(grouping => grouping.Enabled(false))
                                                                                             .Footer(true)
                                                                 )

“事实”的整数编辑器模板代码&amp; “行动”栏目如下。

@(Html.Telerik().IntegerTextBox()
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
            .InputHtmlAttributes(new { style = "width:100%", pattern = "[0-9]*" })
    .MinValue(1)
    .MaxValue(5)
    .Value(Model)        

请提供解决方案。任何帮助表示赞赏。

2 个答案:

答案 0 :(得分:2)

以下是我建议您解决的问题,因为您的目标不支持开箱即用。

随意优化/更改实现或使其更通用(例如,使用类来查找单元格而不依赖于索引)

 $(function () {
    $('#persons tbody').on('keydown', function (e) {
        if (e.keyCode == 9) {
            var currentCell = $(e.target).closest('td');
            var cellIndex = currentCell.index();
            if (cellIndex == 2 || cellIndex == 4) { //if editing cell in third or fifth column, use different indexes if needed
                e.stopPropagation();
                e.preventDefault();
                var grid = $('#persons').data().kendoGrid;

                if (cellIndex == 2) {
                    var cellToEdit = currentCell.parent().find('td:eq(4)');
                    grid._handleEditing(currentCell, cellToEdit);  
                }
                if (cellIndex == 4) {
                    var cellToEdit = currentCell.parent().find('td:eq(2)');
                    grid._handleEditing(currentCell, cellToEdit);   
                }
                setTimeout(function () {
                    cellToEdit.find('input').focus();
                })
            }
        }
    })
})

答案 1 :(得分:0)

我不确定如何做到这一点,但您是否尝试使用tabindex之类的东西,也许是在htmlAttributes中使用它?无论如何,我从来没有做过这样的事情,但也许你可以尝试一下这个领域:

columns.Bound(p => p.Facts).Width("8%").HtmlAttributes(new { tabindex = 1 });
columns.Bound(p => p.Actions).Title("Practice").Width("8%").HtmlAttributes(new { tabindex = 2 });

由于您使用的是Telerik Grid,因此您可能需要在每个项目中以某种方式混合使用它。然后,也许我误解了你的观点(我已经知道这样做了):)