最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Bind Click Event to Kendo ToolBar - Stack Overflow

matteradmin6PV0评论

I am trying to bind click event to buttons I have in kendo Tool bar. I am creating button using template. I am using Kendo Jquery with angular. Any help will be highly appreciated.

So far I have tried this using Kendo Jquery Documentation:

<!DOCTYPE html>
<html>

<head>
    <base href="">
    <style>
        html {
            font-size: 14px;
            font-family: Arial, Helvetica, sans-serif;
        }
    </style>
    <title></title>
    <link rel="stylesheet" href=".3.1023/styles/kendo.default-v2.min.css" />

    <script src=".3.1023/js/jquery.min.js"></script>
    <script src=".3.1023/js/kendo.all.min.js"></script>

</head>

<body>
    <div id="example">
        <div class="demo-section k-content wide">
            <div id="toolbar"></div>
        </div>
        <script>
            $(document).ready(function () {
                $("#toolbar").kendoToolBar({
                    items: [
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-save'></span>Save</a>"
                        },
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon  k-i-arrows-swap'></span>Top/Bottom</a>"
                        },
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-pencil'></span>Edit</a>"
                        },
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-calendar'></span>Schedule</a>",
                            click: onButtonClick()
                        },

                        {
                            type: "splitButton",
                            text: "Download",
                            menuButtons: [{
                                    text: "PDF",
                                    icon: "k-i-pdf"
                                },
                                {
                                    text: "EXCEL",
                                    icon: "k-i-excel"
                                }
                            ]
                        },

                        {
                            type: "button",
                            text: "Action",
                            overflow: "always"
                        },
                        {
                            type: "button",
                            text: "Another Action",
                            overflow: "always"
                        },
                        {
                            type: "button",
                            text: "Something else here",
                            overflow: "always"
                        }
                    ]
                });

                $("#dropdown").kendoDropDownList({
                    optionLabel: "Paragraph",
                    dataTextField: "text",
                    dataValueField: "value",
                    dataSource: [{
                            text: "Heading 1",
                            value: 1
                        },
                        {
                            text: "Heading 2",
                            value: 2
                        },
                        {
                            text: "Heading 3",
                            value: 3
                        },
                        {
                            text: "Title",
                            value: 4
                        },
                        {
                            text: "Subtitle",
                            value: 5
                        }
                    ]
                });
            });

            function onButtonClick() {
                alert('clicked')
            }
        </script>
    </div>
</body>

</html>

Dojo for the same: /@amitdwivedi/uDOFeWev

I am trying to bind click event to buttons I have in kendo Tool bar. I am creating button using template. I am using Kendo Jquery with angular. Any help will be highly appreciated.

So far I have tried this using Kendo Jquery Documentation:

<!DOCTYPE html>
<html>

<head>
    <base href="https://demos.telerik./kendo-ui/toolbar/index">
    <style>
        html {
            font-size: 14px;
            font-family: Arial, Helvetica, sans-serif;
        }
    </style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik./2019.3.1023/styles/kendo.default-v2.min.css" />

    <script src="https://kendo.cdn.telerik./2019.3.1023/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik./2019.3.1023/js/kendo.all.min.js"></script>

</head>

<body>
    <div id="example">
        <div class="demo-section k-content wide">
            <div id="toolbar"></div>
        </div>
        <script>
            $(document).ready(function () {
                $("#toolbar").kendoToolBar({
                    items: [
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-save'></span>Save</a>"
                        },
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon  k-i-arrows-swap'></span>Top/Bottom</a>"
                        },
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-pencil'></span>Edit</a>"
                        },
                        {
                            template: "<a href='' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-calendar'></span>Schedule</a>",
                            click: onButtonClick()
                        },

                        {
                            type: "splitButton",
                            text: "Download",
                            menuButtons: [{
                                    text: "PDF",
                                    icon: "k-i-pdf"
                                },
                                {
                                    text: "EXCEL",
                                    icon: "k-i-excel"
                                }
                            ]
                        },

                        {
                            type: "button",
                            text: "Action",
                            overflow: "always"
                        },
                        {
                            type: "button",
                            text: "Another Action",
                            overflow: "always"
                        },
                        {
                            type: "button",
                            text: "Something else here",
                            overflow: "always"
                        }
                    ]
                });

                $("#dropdown").kendoDropDownList({
                    optionLabel: "Paragraph",
                    dataTextField: "text",
                    dataValueField: "value",
                    dataSource: [{
                            text: "Heading 1",
                            value: 1
                        },
                        {
                            text: "Heading 2",
                            value: 2
                        },
                        {
                            text: "Heading 3",
                            value: 3
                        },
                        {
                            text: "Title",
                            value: 4
                        },
                        {
                            text: "Subtitle",
                            value: 5
                        }
                    ]
                });
            });

            function onButtonClick() {
                alert('clicked')
            }
        </script>
    </div>
</body>

</html>

Dojo for the same: https://dojo.telerik./@amitdwivedi/uDOFeWev

Share Improve this question edited Nov 14, 2019 at 12:21 Amit asked Nov 14, 2019 at 8:28 AmitAmit 1,4911 gold badge17 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

According to the Telerik Docs for the toolbar Click function, the click event handler is only applicable for toolbar items of type button or splitButton. But, items with a template do not have a type.

So, you need to either use basic buttons instead of templates (then you can use the Telerik click handler), or put the click handler in the template itself like this:

$(document).ready(function() {
  $("#toolbar").kendoToolBar({
    items: [
      {
        template: "<a href='' onclick='onButtonClick()' class='k-icon-text-button k-button k-button-icontext k-toolbar-first-visible'><span class='k-icon k-i-save'></span>Save</a>"
        //                    ^^^^^^^^^^^^^^^^^^^^^^^^^
      }
    ]
  });
});

function onButtonClick(){
  alert('clicked')
}

Example Dojo: https://dojo.telerik./UniqiHuF/4

Post a comment

comment list (0)

  1. No comments so far