[英]Javascript validation on paging in kendo ui grid
The following code worked as expected, however on the paging click, it still execute and display message "Please select a record first, then press this button". 下面的代码按预期工作,但是在单击分页时,它仍然执行并显示消息“请先选择一条记录,然后按此按钮”。 Is there anyway to prevent this unless the export button click. 无论如何,除非单击导出按钮,否则可以防止这种情况发生。 Thank you 谢谢
$(document).ready(function () {
$("#Product").on("click",function(){
var $exportLink = $('#export');
var href = $exportLink.attr('href');
var grid = $('#Product').data('kendoGrid'); //get a reference to the grid data
var record = grid.dataItem(grid.select()); //get a reference to the currently selected row
if(record !=null)
{
href = href.replace(/refId=([^&]*)/, 'refId='+record.ID);
$exportLink.attr('href', href);
}
else
{
alert("Please select a record first, then press this button")
return false;
}
});
});
Defining a click handler as $("#Product").on("click",function(){...})
you are actually defining it for any click on #Product
not just on you Export
button. 将单击处理程序定义为$("#Product").on("click",function(){...})
,实际上是为#Product
上的任何单击而不只是在“ Export
按钮上定义它。 You should define the on
for the button
and not for the grid
您应该为button
而不是为grid
定义on
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.