lox*_*dog 11 jquery kendo-ui kendo-grid kendo-asp.net-mvc kendo-tooltip
我正在努力尝试在网格单元上显示一个Kendo工具提示,从ajax调用中获取内容.我的工具提示声明如下所示:
var grid = $("#myGrid").data("kendoGrid");
grid.table.kendoTooltip({
width: 300,
height: 200,
opacity: 0,
callout: true,
position: 'right',
animation:
{
close: {
effects: "fade:out"
},
open: {
effects: "fade:in",
duration: 1000
}
},
contentTemplateId: "tooltipTemplate",
filter: "td",
show: function (e) {
},
content: function (e) {
var target = e.target;
currentTarget = target;
var message = "Loading...";
if ($(currentTarget[0]).attr("name") !== undefined) {
//Do ajax call, show tool tip
}
else {
//CLOSE THE TOOTLIP
return false;
}
}
});
Run Code Online (Sandbox Code Playgroud)
在那个底部"else",我想关闭或隐藏工具提示,因为我没有属性"name",它被传递到我的ajax调用以显示内容.我已经尝试了以下所有方法:
$("#myGrid").data("kendoGrid").table.kendoTooltip.hide();
$("#myGrid").data("kendoTooltip").hide();
e.sender.popup.destroy();
e.sender.popup.hide();
e.sender.popup.close();
Run Code Online (Sandbox Code Playgroud)
这些都不起作用!Destroy是最接近的,但是当我再次需要它时,我无法重新创建工具提示.有什么建议?
Lar*_*ner 16
工具提示的实施方式使这很困难.你可以调用this.hide()包裹在a中setTimeout,但它会产生闪烁效果.所以你可能不得不为此推出自己的解决方案.这是一个让你入门的想法:
创建一个beforeShow在显示工具提示之前触发的伪事件(这可以以更复杂的方式完成):
// customize the _show method to call options.beforeShow
// to allow preventing the tooltip from being shown..
kendo.ui.Tooltip.fn._show = function (show) {
return function (target) {
var e = {
sender: this,
target: target,
preventDefault: function () {
this.isDefaultPrevented = true;
}
};
if (typeof this.options.beforeShow === "function") {
this.options.beforeShow.call(this, e);
}
if (!e.isDefaultPrevented) {
// only show the tooltip if preventDefault() wasn't called..
show.call(this, target);
}
};
}(kendo.ui.Tooltip.fn._show);
Run Code Online (Sandbox Code Playgroud)
像这样使用它有条件地防止显示工具提示:
var toolTip = $('#grid').kendoTooltip({
filter: ".tooltip",
beforeShow: function (e) {
if ($(e.target).data("name") === null) {
// don't show the tooltip if the name attribute contains null
e.preventDefault();
}
},
content: function (e) {
var row = $(e.target).closest("tr");
var dataItem = grid.dataItem(row);
return "<div>Hi, this is a tool tip for id " + dataItem.Id + "! </div>";
}
}).data("kendoTooltip");
Run Code Online (Sandbox Code Playgroud)
(演示)
The*_*Man 12
我刚刚遇到这个并找到了一个非常好的解决方案.该content事件可以工作就像一个beforeShow事件,因为放映事件被触发之前,它实际上是调用.如果我们将其视为一个beforeShow事件,我们就可以做到这一点
var grid = $("#myGrid").data("kendoGrid");
grid.table.kendoTooltip({
width: 300,
height: 200,
opacity: 0,
callout: true,
position: 'right',
animation:
{
close: {
effects: "fade:out"
},
open: {
effects: "fade:in",
duration: 1000
}
},
contentTemplateId: "tooltipTemplate",
filter: "td",
show: function (e) {
},
content: function (e) {
var target = e.target,
currentTarget = target;
// hide popup as default action
e.sender.popup.element.css("visibility", "hidden");
if ($(currentTarget[0]).attr("name") !== undefined) {
e.sender.popup.element.css("visibility", "visible");
//Do ajax call, show tool tip
$.getJSON("SomeUrl").then(function(response) {
$(target).text(response);
});
return "Loading...";
}
return "";
}
});
Run Code Online (Sandbox Code Playgroud)
小智 5
我希望我的帖子还不算太晚,但会对我们中的一些人有所帮助。这可以通过显示和隐藏事件来实现,我们可以验证工具提示文本并显示或隐藏工具提示,如下所示,这对我有用。
show: function(e){
if(this.content.text() !=""){
$('[role="tooltip"]').css("visibility", "visible");
}
},
hide: function(){
$('[role="tooltip"]').css("visibility", "hidden");
},
Run Code Online (Sandbox Code Playgroud)
完整代码:
$("#GridId").kendoTooltip({
filter: "td:nth-child(1)", //this filter selects the second column's cells
position: "right",
autoHide: false,
show: function(e){
if(this.content.text() !=""){
$('[role="tooltip"]').css("visibility", "visible");
}
},
hide: function(){
$('[role="tooltip"]').css("visibility", "hidden");
},
content: function(e){
var dataItem = $("#GridId").data("kendoTreeList").dataItem(e.target.closest("tr"));
var content = dataItem.ToolTip;
if (content!=null) {
return content;
}
else {
return "";
}
}
}).data("kendoTooltip");
Run Code Online (Sandbox Code Playgroud)