admin管理员组文章数量:1355721
I've added the custom click handler for Kendo grid's "Add new record" button, but JavaScript's preventDefault() function does not seem to work on it.
$('.k-header').on('click', '.k-grid-add', function(e) {
e.preventDefault();
e.stopPropagation();
// do something else
});
I would like that "Add new record" button does something else than adds the new row in grid.
Full code example: JSFIDDLE
I've added the custom click handler for Kendo grid's "Add new record" button, but JavaScript's preventDefault() function does not seem to work on it.
$('.k-header').on('click', '.k-grid-add', function(e) {
e.preventDefault();
e.stopPropagation();
// do something else
});
I would like that "Add new record" button does something else than adds the new row in grid.
Full code example: JSFIDDLE
Share Improve this question asked Nov 7, 2014 at 8:40 CuriousSuperheroCuriousSuperhero 6,6714 gold badges31 silver badges52 bronze badges3 Answers
Reset to default 2This works
$('.k-grid-add').click(function(e) {
// do something else
return false;
});
See updated fiddle
http://jsfiddle/qoxvaayn/5/
KendoUi also attached click event listener like jquery, so to remove an existing click event handler we should use off
like below and then attach new click event.
e.preventDefault();e.stopPropagation(); will stop default event handler behavior but not attached listeners.
$('.k-header').off('click').on('click', '.k-grid-add', function(e) {
//handler business logic here
});
(Alternative)
Add a template and create a custom toolbar button "Add New Records" and attached a event on that buuton
some thing like this
<script type="text/x-kendo-template" id="template">
<input type="button" value="Add new record" onClick="YOURFUNCTION()" class="k-button"/>
</script>
<script>
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 550,
toolbar: [{text: "", template: kendo.template($("#template").html())}],
columns: [
"ProductName",
{ field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "120px" },
{ field: "UnitsInStock", title:"Units In Stock", width: "120px" },
{ field: "Discontinued", width: "120px" },
{ mand: ["edit", "destroy"], title: " ", width: "200px" }],
editable: "inline"
});
});
</script>
本文标签: javascriptpreventDefault() does not work in Kendo grid39s custom click handlerStack Overflow
版权声明:本文标题:javascript - preventDefault() does not work in Kendo grid's custom click handler - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744035388a2579676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论