2013-07-04 41 views
1

我開發了一個簡單的web應用程序,使用一些kendo ui工具。如何使用Enter鍵添加新記錄在kendo網格中

在那裏我用劍道網工具來查看和插入產品詳細信息的數據。

但我的問題是編輯模式(當我插入新記錄),當我按下回車鍵我需要去下一個單元格(在同一行的下一列),後最後一列然後進入下一行(新記錄)。

這裏是利用電網的代碼IM在我視圖「index.cshtml」

button class="k-button" id="batchGrid"> 
    Batch Edit</button> 
<div id="example" class="k-content"> 
    <div id="batchgrid"> 
    </div> 
</div> 
<script> 
    $("#batchGrid").click(function() { 
     var crudServiceBaseUrl = "http://demos.kendoui.com/service", 
         dataSource = new kendo.data.DataSource({ 
          transport: { 
           read: { 
            url: crudServiceBaseUrl + "/Products", 
            dataType: "jsonp" 
           }, 
           update: { 
            url: crudServiceBaseUrl + "/Products/Update", 
            dataType: "jsonp" 
           }, 
           destroy: { 
            url: crudServiceBaseUrl + "/Products/Destroy", 
            dataType: "jsonp" 
           }, 
           create: { 
            url: crudServiceBaseUrl + "/Products/Create", 
            dataType: "jsonp" 
           }, 
           parameterMap: function (options, operation) { 
            if (operation !== "read" && options.models) { 
             return { models: kendo.stringify(options.models) }; 
            } 
           } 
          }, 
          batch: true, 
          pageSize: 20, 
          schema: { 
           model: { 
            id: "ProductID", 
            fields: { 
             ProductID: { editable: false, nullable: true }, 
             ProductName: { validation: { required: true} }, 
             UnitPrice: { type: "number", validation: { required: true, min: 1} }, 
             Discontinued: { type: "boolean" }, 
             UnitsInStock: { type: "number", validation: { min: 0, required: true} } 
            } 
           } 
          } 
         }); 

     $("#batchgrid").kendoGrid({ 
      dataSource: dataSource, 
      navigatable: true, 
      filterable: true, 
      pageable: true, 
      height: 430, 
      width: 300, 
      toolbar: ["create", "save", "cancel"], 
      columns: [ 
          "ProductName", 
          { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "130px" }, 
          { field: "UnitsInStock", title: "Units In Stock", width: "130px" }, 
          { field: "Discontinued", width: "130px" }, 
          { command: ["destroy"], title: "&nbsp;", width: "100px"}], 
      editable: true 
     }); 
    }); 
</script> 

如何處理劍道電網輸入按鍵事件,辦理行和列?

請幫我這裏。

回答

0

試試這個代碼。

$("#batchgrid").on("click", "td", function (e) { 

      var rowIndex = $(this).parent().index(); 
      var cellIndex = $(this).index(); 
      $("input").on("keydown", function (event) { 
       if (event.keyCode == 13) { 
        $("#batchgrid").data("kendoGrid").editCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").next().focusin($("#batchgrid").data("kendoGrid").closeCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").parent()))); 
        return false; 
       } 
      }); 

     }); 
+0

這也給出了同樣的問題,先生.. – sanzy

+0

我真的索裏先生,但問題仍然there.i認爲問題是組合框。當我按下輸入文本框中它將跳轉到下一個單元格,無論有什麼,但是當我按下組合框或複選框或下拉菜單中輸入它將無法正常工作如在文本框中,如果你可以請給我一個合適的解決方案。 – sanzy

0

試試這個代碼就幫你們把下一個單元格輸入時按鍵,

$(document).ready(function() { 
     $("#batchGrid").on("click", "td", function (e) { 
      var rowIndex = $(this).parent().index(); 
      var cellIndex = $(this).index(); 
      window.onkeydown = function (event) { 
       if (event.keyCode == 13) { 
        $("#batchGrid").data("kendoGrid").editCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").next().focusin($("#batchGrid").data("kendoGrid").closeCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").parent()))); 

       } 
      } 

     }); 
    }); 
+0

我想你的代碼,但它沒有給出任何正面feedback.when我按ENTER鍵不移動到下一個cell.kindly請給你的注意這裏.. – sanzy

+0

嗨,我張貼新的代碼。 – Jaimin

0

試試這個

$("#batchgrid").on("click", "td", function (e) { 

      var rowIndex = $(this).parent().index(); 
      var cellIndex = $(this).index(); 
      $(".k-textbox").on("keydown", function (event) { 
       if (event.keyCode == 13) { 
        $("#batchgrid").data("kendoGrid").editCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").next().focusin($("#batchgrid").data("kendoGrid").closeCell($(".k-grid-content").find("table").find("tbody").find("tr:eq(" + rowIndex + ")").find("td:eq(" + cellIndex + ")").parent()))); 
        return false; 
       } 
      }); 

     }); 
+0

到目前爲止它的工作,如果我只使用文本框,但問題是當我按下組合框中的回車鍵或複選框它不能正常工作。如何解決? – sanzy

+0

嗨,我再次發佈新代碼。我希望這次對你有用。 – Jaimin

+0

我真的sory先生,但問題仍然there.i認爲問題是組合box.when我按下輸入文本框中它將跳轉到下一個單元格,無論有什麼,但是當我按下輸入組合框或複選框或下拉它將無法正常工作,如在textbox.if你可以請給我一個適當的解決方案。 – sanzy

相關問題