简体   繁体   English

Extjs如何更改网格调整大小的工具提示?

[英]Extjs how to change tooltip on grid resize?

Show tooltip to overflowed grid cell. 向溢出的网格显示工具提示。

If the content of the cell do not fit in its visible part, I want to show tooltip with the full text of this cell and if its not don't show it. 如果该单元格的内容不适合其可见部分,我想显示带有该单元格全文的工具提示,如果不显示,则不显示。 Any ideas how can I do it ? 有什么想法我该怎么做?

// think about smth like this
// but don't know how to get content width

text: 'someHeaderName',
listeners: {
    resize( th, newWidth, height, oldWidth, oldHeight, eOpts ) {
        if (newWidth <= contentWidth) {
            this.showTooltip = true;
            th.up('panel').getView().refresh();
        }
    }
},
renderer: function(val, meta, rec, rowIndex, colIndex, store, view) {
    if (this.showTooltip) {
        meta.tdAttr = 'data-qtip="' + val + '"';
    }
    return val;
}

Change your renderer function like this. 像这样更改渲染器功能。 Make sure x-grid-cell-inner is your grid inner cell class otherwise replace with your css class name. 确保x-grid-cell-inner是您的网格内部单元格类,否则请替换为您的CSS类名。 To refresh after every column resize use getView().refresh() function and remove otherlines from your resize listeners. 要在每列调整大小之后刷新,请使用getView().refresh()函数,并从调整大小的侦听器中删除其他行。

 listeners: {
  resize( th, newWidth, height, oldWidth, oldHeight, eOpts ) {
                th.up('panel').getView().refresh();
           }
 },
 renderer: function(val, meta, rec, rowIndex, colIndex, store, view) {
    var colWidth = this.getColumns()[colIndex].width;
    var innercellclassEl = document.getElementsByClassName('x-grid-cell-inner ');
    var contentWidth = Ext.util.TextMetrics.measure(innercellclassEl,val).width;
    if ( colWidth < contentWidth) {
      meta.tdAttr = 'data-qtip="' + val + '"';
    }
    return val;
 }

My solution: 我的解决方案:

this.tip = Ext.create('Ext.tip.ToolTip', {
    target: Ext.getBody(),
    delegate: '.x-grid-cell',
    trackMouse: true,
    listeners: {
        beforeshow: function(tip) {
            var cell = tip.triggerElement;
            var el = cell.children[0];

            if (el.offsetWidth >= el.scrollWidth || cell.getAttribute('data-qtip')) {
                return false;
            }

            tip.update(el.innerText);
        }
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM