我启用了行选择的网格和一个命令按钮(带有点击事件)
"通常"当我按下按钮按钮时,选择相应的行,然后触发按钮的点击事件 这是正确的行为,我想要! 但是"有时"行的选择不会被激活,只会触发按钮的点击事件
我无法在小提琴上复制所有代码,但我会在下面给出您的详细信息
[剑道使用版本:Kendo UI Complete v2013.1.319]
var Master = {};
Master._height = null;
Master._resSolDataSource = null;
Master._followUpDataSource = null;
Master._filter = {};
Master.SelectedDocument = {};
Master.followUpWindow = null;
Master.init = function () {
Master._resSolDataSource = new kendo.data.DataSource({
.........
....
});
//Inizialize the adminGrid
$("#adminGrid").kendoGrid({
autoBind: false,
dataSource: Master._resSolDataSource,
selectable: true,
pageable: true,
change: Master.onRowChange,
heigt: 300,
columns: [{
field: "Id",
hidden: true
}, {
field: "Piva",
title: "Partiva IVA"
}, {
field: "RagioneSociale",
title: "Ragione Sociale"
}, {
field: "Data",
format: "{0:dd/MM/yyyy}"
}, {
field: "Diniego",
title: "Diniego"
}, {
field: "AnnoRiferimento",
title: "Anno di riferimento"
}, {
field: "MeseRiferimento",
title: "Mese di riferimento"
}, {
field: "Stato"
}, {
command: [
{
name: "download",
click: Master.download
}
],
title: " ",
width: 180
}]
});
//double click has the same behaviour of the button click
$("#adminGrid").delegate("tbody>tr[role=row]", "dblclick", Master.download);
$("#btnSearch").click(function () {
.....
....
//load data
Master._resSolDataSource.read();
});
}
//richiamato ogni volta che si clicca su una riga (se la griglia è selectable: true)
Master.onRowChange = function () {
var model = this.dataItem(this.select());
Master.SelectedDocument = {};
Master.SelectedDocument.IdDocument = model.Id;
Master.SelectedDocument.Stato = model.Stato;
Master.SelectedDocument.AnnoRiferimento = model.AnnoRiferimento;
Master.SelectedDocument.MeseRiferimento = model.MeseRiferimento;
Master.SelectedDocument.Piva = model.Piva;
}
//this is called by the button's click
Master.download = function (e) {
//e.preventDefault();
var selDoc = {};
selDoc.IdDocument = Master.SelectedDocument.IdDocument;
selDoc.status = Master.SelectedDocument.Stato;
selDoc.AnnoRiferimento = Master.SelectedDocument.AnnoRiferimento;
selDoc.MeseRiferimento = Master.SelectedDocument.MeseRiferimento;
selDoc.Piva = Master.SelectedDocument.Piva;
$.ajax({
type: "POST",
url: 'PdfManager/Index',
data: JSON.stringify(selDoc),
contentType: "application/json; charset=utf-8",
//dataType: "text",
dataType: "html",
success: function (event) {
var win = window.open();
win.document.write(event);
}
});
}
1)在第一次我认为这是一个"计时问题" 我以为"有时"选择需要更多时间,因此按钮的点击事件首先发生。为了解决这个问题,我试图通过
包装按钮的点击事件的所有代码的setTimeout(函数(){ .... //单击事件代码 },1000);
但随之而来的问题随机存在
2)我试图使用e.preventDefault();在按钮的点击事件的开头,以避免按钮标记中的某些东西介入,但这不起作用
你可以帮帮我吗?你有什么建议去调查吗?你能建议我学习任何链接,资源,视频,课程来学习像剑道一样的jb框架,一步一步地观察当我点击按钮时内部发生的事情(在我的情况下,了解在什么情况下没有选择行) ) 如果一个人没有这方面的知识,很难调试这样的应用程序
给我一只手pleaseeeee
答案 0 :(得分:1)
单击自定义命令(按钮)时,onChange
事件不会触发,因此Master.SelectedDocument
中没有任何内容,并且未进行选择。从Master.download
函数中进行选择。
请尝试以下代码:
Master.download = function (e) {
e.preventDefault();
// get the row with the button
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
// get the values to your payload object
var selDoc = {};
selDoc.IdDocument = dataItem.IdDocument;
selDoc.status = dataItem.Stato;
selDoc.AnnoRiferimento = dataItem.AnnoRiferimento;
selDoc.MeseRiferimento = dataItem.MeseRiferimento;
selDoc.Piva = dataItem.Piva;
$.ajax({
type: "POST",
url: 'PdfManager/Index',
data: JSON.stringify(selDoc),
contentType: "application/json; charset=utf-8",
//dataType: "text",
dataType: "html",
success: function (event) {
var win = window.open();
win.document.write(event);
}
});
}
此方法会忽略onchange
事件,如果您需要将onchange
用于其他目的,则仍需要更改它。
您可以从自定义命令手动突出显示:
$(e.currentTarget).closest("tr").addClass('highligted')
或者看看这是否有效:
grid.select( $(e.currentTarget).closest("tr"));
答案 1 :(得分:0)
单击“某个时间”按钮会引发事件,有时候不会(我已经使用浏览器的开发工具 - IE / Firefox对此进行了调试)......我不明白为什么。
无论如何,正如你所建议的那样,我将选择带入了
Master.download = function (e) {
e.preventDefault();
var model = this.dataItem($(e.currentTarget).closest("tr"));
Master.SelectedDocument = {};
Master.SelectedDocument.IdDocument = model.Id;
Master.SelectedDocument.Stato = model.Stato;
Master.SelectedDocument.AnnoRiferimento = model.AnnoRiferimento;
Master.SelectedDocument.MeseRiferimento = model.MeseRiferimento;
Master.SelectedDocument.Piva = model.Piva;
......
并且实际上运行良好(GREAT !!!!),从某种意义上说,我得到了正确的数据行,这样我就能正确地做其他事情
但是行没有“突出显示”的问题仍然存在(因为你说我没有发生更改事件)
现在,我可以“以编程方式”选择行来提升onchange事件“always”=