5

I'm trying to create a tooltip for my grid like this:

$("#grid").kendoTooltip({
    autoHide: true,
    showOn: "mouseenter",
    width:125,
    height:125,
    position: "right",
    filter: ".k-grid-content a.hasTooltip",
    content: kendo.template($("#storeTerritory").html())
});

The template definition:

<script type="text/x-kendo-template" id="storeTerritory">
<div class="tooltipcontent">
    #for(var i = 0; i < Territories.length; i++){#
        #if (Territories != 'null' && Territories != '')  {#
            <p>#=Territories[i].TerritoryDescription#</p>
        #} else{#
            <p>Information not available</p>
      #}#
    #}#
</div>
</script>

I've setup a sample here:
http://jsbin.com/iJunOsa/21/edit

I get a ReferenceError: Territories is not defined error in the console when I mouse over on 'Wilton'

Let's say I were to replace the contents of the storeTerritory template with plain-old HTML, then the tooltip appears:

<p>Wilton</p>

What could the issue be?

nouptime
  • 9,929
  • 5
  • 22
  • 37

3 Answers3

7

The problem is that there is no model associated with the tooltip; in order to do what you want, you need to create the content using a function:

$("#grid").kendoTooltip({
    autoHide: true,
    showOn: "mouseenter",
    width: 125,
    height: 125,
    position: "right",
    filter: ".k-grid-content a.hasTooltip",
    content: function (e) {
        var row = $(e.target).closest("tr");
        var dataItem = $("#grid").data("kendoGrid").dataItem(row);

        var template = kendo.template($("#storeTerritory").html());
        return template(dataItem);
    }
});

(updated demo)

Lars Höppner
  • 18,252
  • 2
  • 45
  • 73
  • Sorry to trouble you, I'm facing an issue displaying an image within the tooltip. Would appreciate it if you could have a look at the edited question. – nouptime Apr 24 '14 at 06:14
  • Please don't make edits to questions which change their meaning; instead, ask a new question. – Lars Höppner Apr 24 '14 at 13:05
2
 grid = $("#grid").kendoGrid({
      dataSource: dataSource,
      scrollable: true,
      filterable: true,
      toolbar: ["create"],
      columns: [
        { field: "ID", width: "50px" },
        { field: "Text", width: "200px", attributes: {
          style: 'white-space: nowrap '
        }  }],
      editable: "incell"
    }).data("kendoGrid");

    $("#grid").kendoTooltip({
      filter: "td:nth-child(2)", //this filter selects the second column's cells
      position: "right",
      content: function(e){
        var dataItem = $("#grid").data("kendoGrid").dataItem(e.target.closest("tr"));
        var content = dataItem.Text;
        return content;
      }
    }).data("kendoTooltip");

(Demo)

tom lee
  • 61
  • 7
0

The issue is that in the context of the template (when running it):

<script type="text/x-kendo-template" id="storeTerritory">
    <div class="tooltipcontent">
        #if (Territories != 'null' && Territories != '')  {#
            <p>#=Territories[i].TerritoryDescription#</p>
        #} else{#
            <p>Information not available</p>
        #}#
    </div>
</script>

there is nothing as Territories or as i so it fails.

OnaBai
  • 40,767
  • 6
  • 96
  • 125
  • My bad, some parts of the template code were missing. I've updated the sample but the issue still persists. – nouptime Apr 23 '14 at 00:59