9

我有一个gridview,它附有一个具有一些字段的模型。但是在我的网格中我只显示一个字段,我想要的是当我的鼠标悬停在网格行上时,工具提示会出现并显示其他字段的值。

我怎样才能做到这一点?有人做过吗?

我应该创建工具提示什么网格事件?如何访问我的悬停行值并将其显示在工具提示上?如何显示价值的好方法,可以使用xpanel 之类的工具提示,还是唯一的方法是使用 html?

请帮我。提前致谢 :)

4

5 回答 5

16

Use renderer in grid columns config. write an function which will return the expected value to that renderer function mapping.

Sample working example:

columns: [{
           text     : 'Device Name'
           ,dataIndex: 'name'
           ,renderer : function(value, metadata,record) {
                                    return getExpandableImage(value, metadata,record);
                    }
           }]



function getExpandableImage(value, metaData,record){
    var deviceDetail = record.get('deviceName') + " " + record.get('description');
    metaData.tdAttr = 'data-qtip="' + deviceDetail + '"';
    return value;
}

This is the place (metaData.tdAttr = 'data-qtip="' + deviceDetail + '"';) where you need to show data in tooltip

于 2013-08-19T13:36:32.080 回答
5

您可以使用 sencha 文档中的以下示例

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.tip.ToolTip

var store = Ext.create('Ext.data.ArrayStore', {
    fields: ['company', 'price', 'change'],
    data: [
        ['3m Co',                               71.72, 0.02],
        ['Alcoa Inc',                           29.01, 0.42],
        ['Altria Group Inc',                    83.81, 0.28],
        ['American Express Company',            52.55, 0.01],
        ['American International Group, Inc.',  64.13, 0.31],
        ['AT&T Inc.',                           31.61, -0.48]
    ]
});

var grid = Ext.create('Ext.grid.Panel', {
    title: 'Array Grid',
    store: store,
    columns: [
        {text: 'Company', flex: 1, dataIndex: 'company'},
        {text: 'Price', width: 75, dataIndex: 'price'},
        {text: 'Change', width: 75, dataIndex: 'change'}
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody()
});

var view = grid.getView();
var tip = Ext.create('Ext.tip.ToolTip', {
    // The overall target element.
    target: view.el,
    // Each grid row causes its own separate show and hide.
    delegate: view.itemSelector,
    // Moving within the row should not hide the tip.
    trackMouse: true,
    // Render immediately so that tip.body can be referenced prior to the first show.
    renderTo: Ext.getBody(),
    listeners: {
        // Change content dynamically depending on which element triggered the show.
        beforeshow: function updateTipBody(tip) {
            tip.update('Over company "' + view.getRecord(tip.triggerElement).get('company') + '"');
        }
    }
});
于 2013-08-19T10:19:21.313 回答
0

我在渲染器中使用:

function(value,metadata,record){
    metadata.attr = 'ext:qtip="' + val + '"';
}
于 2015-04-03T13:40:40.983 回答
0

最简单的方法:

当您声明该列时,请使用该属性attribute

{ 
  field: "nameField",
  width: "150px",
  title: "My Field",
  attributes: { title: "#=data.nameField#" }
}
于 2014-11-24T21:09:53.653 回答
0

使用列渲染器功能如下:

{
                id       :'data',
                header   : 'Data', 
                width    : 160, 
                sortable : true, 
                dataIndex: 'data',
                renderer : function(value, metadata,record) {
                    return setTooltip(value, metadata,record);
                }
            }


    function setTooltip(value, metaData, record){
        var deviceDetail = record.get('data') + ": " + record.get('description');
        metaData.attr='ext:qtip="' + deviceDetail + '"';
        console.log("deviceDetail: " + deviceDetail);
        return value;
    }
于 2016-04-19T04:51:28.033 回答