{"id":487,"date":"2012-09-05T01:20:13","date_gmt":"2012-09-05T01:20:13","guid":{"rendered":"http:\/\/garysieling.com\/blog\/?p=487"},"modified":"2012-09-05T01:20:13","modified_gmt":"2012-09-05T01:20:13","slug":"extjs-tooltip-example","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/extjs-tooltip-example\/","title":{"rendered":"ExtJS Tooltip Example"},"content":{"rendered":"<p><strong>Problem<\/strong><br \/>\nYou want to display a grid with a tooltip.<\/p>\n<p><strong>Tested in ExtJS Version<\/strong><br \/>\n4.1.1<\/p>\n<p><strong>Screenshot<\/strong><br \/>\n<a href=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2012\/09\/ext-tooltip-example.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-488\" title=\"ext tooltip example\" src=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2012\/09\/ext-tooltip-example.png\" alt=\"\" width=\"473\" height=\"202\" srcset=\"https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2012\/09\/ext-tooltip-example.png 473w, https:\/\/www.garysieling.com\/blog\/wp-content\/uploads\/2012\/09\/ext-tooltip-example-300x128.png 300w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><\/a><\/p>\n<p><strong>Solution<\/strong><br \/>\nSet the &#8220;tip&#8221; property on the GridPanel&#8217;s view (panel.getView().tip).<\/p>\n<pre lang=\"Javascript\">view = this.getView();\nview.tip = Ext.create('Ext.tip.ToolTip', {\n\ttarget: view.el,\n\tdelegate: view.itemSelector,\n\ttrackMouse: true,\n\trenderTo: Ext.getBody(),\n\tlisteners: {\n     \t\tbeforeshow: function updateTipBody(tip) {\n     \t\t\t tip.update(\"Tooltip!\");\n        }\n}<\/pre>\n<p><strong>Discussion<\/strong><br \/>\nThe example ExtJS provides in their documentation did not work for me. In their example, they run this code in a the render event, which they set after the grid object is created- for whatever reason this only works in afterrender.<\/p>\n<p>You can retrieve the highlighted row inside the beforeshow event using view.getRecord(tip.triggerElement), but it is not clear how to determine which column the tooltip is rendered on.<\/p>\n<p>See the <a href=\"http:\/\/garysieling.com\/blog\/extjs-listview-example\">ExtJS GridView example<\/a> for further discussion.<\/p>\n<p>The full source is below.<\/p>\n<pre lang=\"Javascript\">Ext.onReady(function() {\nvar trackStore = new Ext.data.Store({\n  storeId: 'soundCloudStore',\n\n    proxy: {\n      type: 'ajax',\n      url: 'blues.json',\n      reader: {\n        type: 'json',\n        idProperty: 'id'\n      }\n    },\n    fields:['duration', 'genre', 'created_at', 'title', 'id']\n});\n\ntrackStore.load(\n  function() { \n    Ext.create('Ext.grid.Panel', {\n      title: 'Tracks',\n      store: trackStore,\n      stripeRows: false,\n      columns: [\n        { header: 'Title', dataIndex: 'title' },\n        { header: 'Duration',  dataIndex: 'duration' },\n        { header: 'Genre', dataIndex: 'genre' },\n        { header: 'Created At', dataIndex: 'created_at'}\n      ],\n      height: 200,\n      width: 475,\n      renderTo: Ext.getBody(),\n      listeners: {\n        afterrender: function( eOpts )\n        {\n          view = this.getView();\n          view.tip = Ext.create('Ext.tip.ToolTip', {\n            target: view.el,\n            delegate: view.itemSelector,\n            trackMouse: true,\n            renderTo: Ext.getBody(),\n            listeners: {\n              beforeshow: function updateTipBody(tip) {\n              tip.update(\"Tooltip!\");\n            }\n          }\n        });\n      }\n    }\n  });\n});\n});<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Problem You want to display a grid with a tooltip. Tested in ExtJS Version 4.1.1 Screenshot Solution Set the &#8220;tip&#8221; property on the GridPanel&#8217;s view (panel.getView().tip). view = this.getView(); view.tip = Ext.create(&#8216;Ext.tip.ToolTip&#8217;, { target: view.el, delegate: view.itemSelector, trackMouse: true, renderTo: Ext.getBody(), listeners: { beforeshow: function updateTipBody(tip) { tip.update(&#8220;Tooltip!&#8221;); } } Discussion The example ExtJS provides &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/extjs-tooltip-example\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ExtJS Tooltip Example&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[213,216,218,224,502],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/487"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=487"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/487\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}