我有一个gridview,它附有一个具有一些字段的模型。但是在我的网格中我只显示一个字段,我想要的是当我的鼠标悬停在网格行上时,工具提示会出现并显示其他字段的值。
我怎样才能做到这一点?有人做过吗?
我应该创建工具提示什么网格事件?如何访问我的悬停行值并将其显示在工具提示上?如何显示价值的好方法,可以使用xpanel 之类的工具提示,还是唯一的方法是使用 html?
请帮我。提前致谢 :)
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
您可以使用 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') + '"');
}
}
});
我在渲染器中使用:
function(value,metadata,record){
metadata.attr = 'ext:qtip="' + val + '"';
}
最简单的方法:
当您声明该列时,请使用该属性attribute
:
{
field: "nameField",
width: "150px",
title: "My Field",
attributes: { title: "#=data.nameField#" }
}
使用列渲染器功能如下:
{
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;
}