Search code examples
javascriptkendo-uitooltip

Avoid Showing Kendo Tooltip


Here is my tooltip definition:

var toolTip = $('.static_grid_wrapper').kendoTooltip({
    filter: "tr[role=row]",
    position: "top",
    content: function (e) {
        var target = e.target; 
        var tooltipMessage = "<table>";

        var a = $(target).data("A");
        if (defined(alpari)) {
            tooltipMessage += "<tr><td>A</td><td>" + a + "</td></tr>";
        }
        else {
            tooltipMessage += "<tr><td>A</td><td>NA</td></tr>";
        }

        var l = $(target).data("L");
        if (defined(l)) {
            tooltipMessage += "<tr><td>L</td><td>" + l + "</td></tr>";
        }
        else {
            tooltipMessage += "<tr><td>L</td><td>NA</td></tr>";
        }

        var s = $(target).data("S");
        if (defined(s)) {
            tooltipMessage += "<tr><td>S</td><td>" + s + "</td></tr>";
        }
        else {
            tooltipMessage += "<tr><td>S</td><td>NA</td></tr>";
        }

        var g = $(target).data("G");
        if (defined(g)) {
            tooltipMessage += "<tr><td>G</td><td>" + g + "</td></tr>";
        }
        else {
            tooltipMessage += "<tr><td>G</td><td>NA</td></tr>";
        }

        tooltipMessage += "</table>";
        return tooltipMessage;
    },
    show: function (e) {

    }
}).data("kendoTooltip");

If "a" or "l" or "s" or "g" is undefined, I don't want to show the tooltip. But I couldn't find the method I have to call.


Solution

  • It doesn't look like there's a designated way to do this at the moment. Something like this here will probably work from within your content method:

    // if a or l undefined, don't show the popup ...
    if (!a || !l) {
        // replace the popup that was created with a stub so _show doesn't break
        toolTip.popup = {
            open: function() {},
            one: function() {},
            options: {}
        };
    
        // delete the popup stub
        setTimeout(function () {
            toolTip.popup = null;
        }, 5);
    }
    

    (see demo: there's a tooltip on the third column, and it is hidden for every second row)