【问题标题】:Kendo Grid rowTemplate k-button click function not definedKendo Grid rowTemplate k 按钮单击功能未定义
【发布时间】:2018-09-14 06:48:42
【问题描述】:

我在 Kendo Grid 中使用 K 按钮。为了给每一行着色,我应该使用 rowTemplate 和 altRowTemplate 选项。唯一的问题是点击功能没有正确绑定到按钮。

我收到以下错误,

(index):1 Uncaught ReferenceError: viewProfile is not defined 在 HTMLButtonElement.onclick ((index):1)

代码在这里,

  myGridOptions({
    columns: [
      { field: 'name', title: 'Name', width: '160px'},
      { field: 'address', title: 'address'},
      { field: 'occupation', title: 'Occupation' },          
      { field: 'location', title: 'Location'},
      { field: 'salary', title: 'Salary' },
      { field: 'company', title: 'Company'},
      { field: 'phone', title: 'Phone'},
      //{ field: 'button', title: ' ' }
      { command: { text: 'View Profile', click: viewProfile }, title: ' ', width: '160px' }          
    ],
    dataSource: OccData,
    rowTemplate: '<tr style="background-color: rgb(246,246,246)" data-uid="#= uid #">'+
      '<td>#: name # </td>' +          
      '<td>#: address #</td>' +
      '<td>#: occupation #</td>' +
      '<td>#: location #</td>' +          
      '<td>#: salary #</td>' +
      '<td>#: company #</td>' +          
      '<td> #: phone#</td>' +
      '<td>#: education #</td>' +          
      '<td><button class="k-button" onclick="viewProfile();">View Profile</button></td>'+         
      '</tr>',
      altRowTemplate: '<tr style="background-color: rgb(255,255,255)" data-uid="#= uid #">'+
      '<td>#: name # </td>' +          
      '<td>#: address #</td>' +
      '<td>#: occupation #</td>' +
      '<td>#: location #</td>' +          
      '<td>#: salary #</td>' +
      '<td>#: company #</td>' +          
      '<td> #: phone#</td>' +
      '<td>#: education #</td>' +          
      '<td><button class="k-button" onclick="viewProfile();">View Profile</button></td>'+         
      '</tr>',        
    overflow: false
  });

我参考了几个链接,但在 rowTemplate 中找不到使用点击功能的解决方案。

剑道开发者的任何建议!!对我有帮助。

【问题讨论】:

    标签: javascript kendo-ui kendo-grid


    【解决方案1】:

    在您的列定义中,您指定了点击事件viewProfile。你有一个名为 viewProfile 的 JavaScript 函数吗?

    【讨论】:

    • 是的。我有这个功能。
    【解决方案2】:

    刚刚收到!!

        <div id="grid"></div>
    <script>
    $("#grid").kendoGrid({
      columns: [
        { field: "name" },
        { field: "age" },
        {template: "<button class=\"show\">Show</button>"}
      ],
      dataSource: [
        { name: "Jane Doe", age: 30 },
        { name: "John Doe", age: 33 }
      ],
      dataBound: function(e) {
        //console.log("dataBound");
        this.element.find(".show").bind("click", function() {
        alert("Clicked");
      });
      }
    });
    </script>
    

    感谢https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/events/databound

    它可能对某人有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      相关资源
      最近更新 更多