【问题标题】:How to handle keypress events in a Kendo grid detailTemplate如何在 Kendo 网格 detailTemplate 中处理按键事件
【发布时间】:2015-03-27 00:08:53
【问题描述】:

我有一个带有 detailTemplate(带有一些样式的文本区域)的 Kendo 网格,我正在尝试拦截和处理按键事件。

我尝试过 AngularJS 和 jQuery 模式,但没有成功。

如果有人成功了,我将不胜感激。

【问题讨论】:

    标签: events kendo-ui kendo-grid keypress


    【解决方案1】:

    $("#grid").kendoGrid({
      detailTemplate: kendo.template( $("#template" ).html()),
      detailInit: detailInit
    });
    
    function detailInit(e) {
      var detailRow = e.detailRow;
        var txtArea = detailRow.find(".myTextArea");
        $(txtArea).on("keypress", function(e) {
            console.log(e)
        });
    }
    <div id="gid"></div>
    <script id="template" type="text/x-kendo-template">
      <textarea class="myTextArea"></textarea>		
    </script>

    【讨论】:

    【解决方案2】:

    如果你对 CR 或 Tab 等控制字符感兴趣,那么也可以监听 KeyDown 事件。

    function detailInit(e) {
      var detailRow = e.detailRow;
    
      detailRow.find(".myTextArea").on("keypress", function(e) {
        console.log(e);
      });
      detailRow.find(".myTextArea").on("keydown", function(e) {
        console.log(e);
      });
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      • 2016-05-14
      相关资源
      最近更新 更多