问题
I have an example, a kendo ui grid is added with Backbone.js. In the kendo ui grid I have a buttons to remove rows, but the buttons don't work on mobile devices. If I press a button repeteadly, it sometimes works. Why? I declare the button in kendoGrid.columns so:
{
command: [{
name: "destroy",
text: "Remove",
className: "ob-delete"
}
To remove a row and do something when button is clicked:
$(document).on("click", ".grid tbody tr .ob-delete", function (e) {
var item = grid.dataItem($(this).closest("tr"));
var check = confirm("Delete");
if (check) {
grid.removeRow($(this).closest("tr"));
}
});
Full example
Edit:
I use the kendo ui version: 2012.3.1114
回答1:
Mobile and click event are not best of friends!
In this code you are adding click on the Html element having .ob-delete class which will not fire Kendo's built in click event. Instead, try to implement your delete method as custom command shown in this demo: http://demos.kendoui.com/web/grid/custom-command.html
$(document).ready(function () {
var grid = $("#grid").kendoGrid({
dataSource: {
pageSize: 10,
data: createRandomData(50)
},
pageable: true,
height: 260,
columns: [
{ field: "FirstName", title: "First Name" },
{ field: "LastName", title: "Last Name" },
{ field: "Title" },
{ command: { text: "View Details", click: showDetails }, title: " ", width: "140px" }]
}).data("kendoGrid");
wnd = $("#details")
.kendoWindow({
title: "Customer Details",
modal: true,
visible: false,
resizable: false,
width: 300
}).data("kendoWindow");
detailsTemplate = kendo.template($("#template").html());
});
function showDetails(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
wnd.content(detailsTemplate(dataItem));
wnd.center().open();
}
</script>
or if a custom command is not required, try the default delete event as shown in this demo. http://demos.kendoui.com/web/grid/editing-inline.html
来源:https://stackoverflow.com/questions/14823072/a-button-in-a-kendo-ui-grid-doesnt-work-on-mobile-device