我正在使用此代码在网格的每个行上显示一个自定义工具提示。问题是我必须仅在某些列上显示。如何在Beforeshow事件中检索CellIndex?我已经尝试使用tipp.triggerlement.cellindex和tipp.anchorelement.cellindex,但我得到了未定义的
var tip = Ext.create('Ext.tip.ToolTip', {
// The overall target element.
target: grid.el,
// Each grid row causes its own separate show and hide.
delegate: grid.view.cellSelector,
// 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(tipp) {
}
}
});
尝试以下:
Ext.create('Ext.grid.Panel', {
listeners:{
render:function(grid) {
var view=grid.getView();
view.tip = Ext.create('Ext.tip.ToolTip', {
target: grid.el,
// this gets css query to identify the individual cells
delegate: view.cellSelector,
listeners: {
beforeshow: function(tip) {
var column = view.getGridColumns()[tip.triggerElement.cellIndex];
var record = view.getRecord(tip.triggerElement.parentNode);
tip.update(record.get(column.dataIndex));
}
}
});
}
}
);
首先在网格selType: 'cellmodel',
上放置配置,您可以使用以下代码获取所选单元格的当前帖子。
grid.getSelectionModel().getCurrentPosition();
它将在当前的行和列详细信息以及其他一些详细信息中重新返回,因此您需要在显示提示事件之前访问此数据,并且您返回false,您无需显示。
当我想要(onmouseover)在工具提示单元/列的内容(例如,内容比单元格的宽度更长)时,我使用以下渲染器方法您可以使用所需的价值适应您的情况:
renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
metaData.tdAttr = 'data-qtip= "' + value + '" data-qclass="tipCls" ';
return value;
}
在我的情况下工作正常,很简单。
看一下:https://www.sencha.com/forum/showthread.php?179016-grid-cell-tooltip