tooltip函数getTip()在Extjs 7.X的actioncolumn上不起作用。

huangapple go评论105阅读模式
英文:

tooltip function getTip() not working on actioncolumn Extjs 7.X

问题

getTip函数对我不起作用。

我在我的app.json启动函数中初始化了Ext.tip.QuickTipManager.init();

我的actioncolumn看起来像这样:

xtype: 'actioncolumn',
getTip: function(value, metadata, record, rowIndex, colIndex, store) {
    return "something";
},
flex: 0.75,
style: 'text-align: left;',
width: 25,
align: 'center',
menuDisabled: true,
bind: {
    text: '{filename}'
},
items: [
    {
        handler: function(view, rowIndex, colIndex, item, e, record, row) {
            Application.fireEvent("filefunction", view, rowIndex, colIndex, item, e, record, row);
        },
        getClass: function(v, metadata, r, rowIndex, colIndex, store) {
            return "x-far fa-file-alt";
        },
        iconCls: 'x-far fa-file-alt'
    }
]

它根本不调用getTip()函数。我做错了什么?

文档链接:

Sencha的getTip()文档

英文:

The tooltip function getTip is not working for me.

I initialized Ext.tip.QuickTipManager.init(); in my app.json launch function.

My actioncolumn is looking like this:

xtype: 'actioncolumn',
getTip: function(value, metadata, record, rowIndex, colIndex, store) {
    return "something";
},
flex: 0.75,
style: 'text-align: left;',
width: 25,
align: 'center',
menuDisabled: true,
bind: {
    text: '{filename}'
},
items: [
    {
        handler: function(view, rowIndex, colIndex, item, e, record, row) {
            Application.fireEvent("filefunction", view, rowIndex, colIndex, item, e, record, row);
        },
        getClass: function(v, metadata, r, rowIndex, colIndex, store) {
        return "x-far fa-file-alt";
        },
        iconCls: 'x-far fa-file-alt'
    }
]

It does not call the getTip() function at all. What am i doing wrong?

The docs:

getTip() Documentation by Sencha

答案1

得分: 2

getTip函数只有在您的操作列没有items,只有一个单一的图标时才起作用。例如,像这样修改您的代码会显示工具提示:

{
    xtype: 'actioncolumn',
    // this works with items, with one icon
    getTip: function(value, metadata, record, rowIndex, colIndex, store) {
        return "something";
    },
    iconCls: 'x-far fa-file-alt',
    flex: 0.75,
    style: 'text-align: left;',
    width: 25,
    align: 'center',
    menuDisabled: true,
    bind: {
        text: '{filename}'
    },
}

如果在操作列中有多个项,您必须为每个项单独定义工具提示。您可以使用tooltip配置为操作列中的一个项设置工具提示:

{
    xtype: 'actioncolumn',
    flex: 0.75,
    style: 'text-align: left;',
    width: 25,
    align: 'center',
    menuDisabled: true,
    bind: {
        text: '{filename}'
    },
    items: [
        {
            handler: function(view, rowIndex, colIndex, item, e, record, row) {
                Application.fireEvent("filefunction", view, rowIndex, colIndex, item, e, record, row);
            },
            getClass: function(v, metadata, r, rowIndex, colIndex, store) {
                return "x-far fa-file-alt";
            },
            iconCls: 'x-far fa-file-alt',
            // add this for fixed tooltip on the item
            tooltip: 'something',
        }
    ]
}

这是一个静态工具提示,固定在列中的一个操作上。如果您需要它是动态的,例如根据记录值,您可以为每个项使用getClass函数来实现:

{
    xtype: 'actioncolumn',
    flex: 0.75,
    style: 'text-align: left;',
    width: 25,
    align: 'center',
    menuDisabled: true,
    bind: {
        text: '{filename}'
    },
    items: [
        {
            handler: function(view, rowIndex, colIndex, item, e, record, row) {
                Application.fireEvent("filefunction", view, rowIndex, colIndex, item, e, record, row);
            },
            getClass: function(v, meta, r, rowIndex, colIndex, store) {
                // set dynamic tooltip with these two lines
                var tooltip = 'something dynamic';
                meta.tdAttr = Ext.String.format('data-qtip="{0}"', tooltip);
                return "x-far fa-file-alt";
            },
            iconCls: 'x-far fa-file-alt'
        }
    ]
}
英文:

The getTip function will only work if your action column does not have items, only a single icon. For example, modifying your code like this does display the tooltip:

{
    xtype: 'actioncolumn',
    // this works with items, with one icon
    getTip: function(value, metadata, record, rowIndex, colIndex, store) {
        return "something";
    },
    iconCls: 'x-far fa-file-alt',
    flex: 0.75,
    style: 'text-align: left;',
    width: 25,
    align: 'center',
    menuDisabled: true,
    bind: {
        text: '{filename}'
    },
}

If you have multiple items in the action column, you have to define tooltip separately for each item. You can set the tooltip for one item in the action column using the tooltip configuration:

{
    xtype: 'actioncolumn',
    flex: 0.75,
    style: 'text-align: left;',
    width: 25,
    align: 'center',
    menuDisabled: true,
    bind: {
        text: '{filename}'
    },
    items: [
        {
            handler: function(view, rowIndex, colIndex, item, e, record, row) {
                Application.fireEvent("filefunction", view, rowIndex, colIndex, item, e, record, row);
            },
            getClass: function(v, metadata, r, rowIndex, colIndex, store) {
                return "x-far fa-file-alt";
            },
            iconCls: 'x-far fa-file-alt',
            // add this for fixed tooltip on the item
            tooltip: 'something',
        }
    ]
}

This is a static tooltip, fixed for one action in the column. If you need it dynamic, for example dependant on the record value, you can use the getClass function for that for each item:

{
    xtype: 'actioncolumn',
    flex: 0.75,
    style: 'text-align: left;',
    width: 25,
    align: 'center',
    menuDisabled: true,
    bind: {
        text: '{filename}'
    },
    items: [
        {
            handler: function(view, rowIndex, colIndex, item, e, record, row) {
                Application.fireEvent("filefunction", view, rowIndex, colIndex, item, e, record, row);
            },
            getClass: function(v, meta, r, rowIndex, colIndex, store) {
                // set dynamic tooltip with these two lines
                var tooltip = 'something dynamic';
                meta.tdAttr = Ext.String.format('data-qtip="{0}"', tooltip);
                return "x-far fa-file-alt";
            },
            iconCls: 'x-far fa-file-alt'
        }
    ]
}

huangapple
  • 本文由 发表于 2023年6月19日 21:36:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76507177.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定