向 KendoGrid 工具栏添加自定义按钮问题

问题描述 投票:0回答:5

您好,我已在 KendoUI 网格的工具栏上添加了一个按钮,但我有几个问题,希望有人可以提供帮助。

  1. 我尝试在按钮旁边添加一个剑道 Web 图标,但它没有呈现。
  2. 当我单击工具栏中的按钮时,我在控制台中看到以下错误:

未捕获的引用错误:未定义 sendEmail。

我不明白为什么它没有看到我的功能。仅出于测试目的,我会显示警报,直到它看到为止。

toolbar: [
            { name: "create", text: "Add" },
            { template: "<input type='button' class='k-button' value='Email Users' onclick='sendEmail()' />",
              imageclass: "k-icon k-i-pencil" }
        ]

function sendEmail() {
   debugger;
   alert('Send Emails');
}

有人可以帮忙吗?

kendo-grid toolbar
5个回答
4
投票

您可以使用如下:

 toolbar: [
 {
    name: "Add",
    text: "Send Email",
    click: function(e){alert('Send Emails'); return false;}
 }
],

3
投票

根据文档,您需要返回您希望在单击时发生的功能。像这样:

 template: '<a class="k-button" href="\\#" onclick="return toolbar_click()">Command</a>'

文档

我希望有帮助。


0
投票

这对我有用:

  1. 您必须在变量中定义网格
  2. 初始化网格并在工具栏选项中添加按钮 工具栏:[{名称:“myButton”,文本:“这是您的按钮文本”}]
  3. 初始化后编写此代码来查找按钮并添加功能:

grid.find(".k-grid-toolbar").on("click", ".k-grid-myButton", function (e) { 警报(“工作了”);});


0
投票

有很多方法可以使用它。请使用下面的例子。

  toolbar: [
       //{ template: kendo.template($("#k-tmpl-toolbar").html()) },
       { name: "Add", template: kendo.template("<button class='k-button k-button-sm k-rounded-md k-button-solid k-button-solid-primary' onclick='AddNewRecord()'>Add New</button>") },
       { name: "search" },
       //{ name: "create", title: "New" },
   ],

-1
投票

你的函数sendEmail()是在document.ready中初始化的还是$(()=>{});如果没有,您将必须初始化它,否则您可以使用这种方式 为按钮添加一个 id 并将其写入 document.ready 中(从按钮标签中删除 onlcick)。

$("#examplebuttonid").click(()=>{
//write your code in here
});

© www.soinside.com 2019 - 2024. All rights reserved.