我正在使用 Ext Scheduler ( http://www.bryntum.com/products/scheduler/ ) 构建简单的应用程序。 我正在尝试为树列添加自定义渲染器,该树列将具有树中人物的图标。
我已经为该列创建了渲染:
renderer: function (v, m, r) {
if (r.get('leaf')) {
return '<div style="float: left">' +
r.get('Name') +
'</div>'+
'<img data-qtip="<img src=iconUrl.png width=60px height=60px/>" '+
'src="iconUrl.png" '+
'width="20px" height="20px" style="float: right; margin-right: 5px"/>';
}
return v;
}
这看起来不错,但对于长名称,我会得到不想要的外观:
查看代码我发现了一些不需要的标记:
我需要的是与标准树列中几乎相同的渲染器,但我需要在该列的右侧添加额外的图标 - 员工图像缩略图。
我在搜索文档时发现有一个名为 cellTpl
的私有(private)属性 ( http://docs.sencha.com/extjs/4.2.1/source/Column2.html#Ext-tree-Column )
但我不知道应该如何更改它以及是否应该更改它,因为它在顶部被标记为私有(private)。
我应该如何更改渲染器才能获得最后一张图像的效果?
这是一些可以玩的jsfiddle:http://jsfiddle.net/Misiu/gwFdr/
最佳答案
我结束了将 Ext.tree.Column
扩展为显示缩略图而不是普通的叶子图标。
这是我的代码:
Ext.define('Grafik.component.tree.Column2', {
extend: 'Ext.tree.Column',
alias: 'widget.treecolumn2',
thumbnailsServiceUrl:'',
cellTpl: [
'<tpl for="lines">',
'<img src="{parent.blankUrl}" class="{parent.childCls} {parent.elbowCls}-img ',
'{parent.elbowCls}-<tpl if=".">line<tpl else>empty</tpl>"/>',
'</tpl>',
'<img src="{blankUrl}" class="{childCls} {elbowCls}-img {elbowCls}',
'<tpl if="isLast">-end</tpl><tpl if="expandable">-plus {expanderCls}</tpl>"/>',
'<tpl if="checked !== null">',
'<input type="button" role="checkbox" <tpl if="checked">aria-checked="true" </tpl>',
'class="{childCls} {checkboxCls}<tpl if="checked"> {checkboxCls}-checked</tpl>"/>',
'</tpl>',
'<img src="{loginUrl}" class="{childCls} {baseIconCls} ',
'{baseIconCls}-<tpl if="leaf">leaf<tpl else>parent</tpl> {iconCls}"',
'<tpl if="icon">style="background-image:url({icon})"</tpl>/>',
'<tpl if="href">',
'<a href="{href}" target="{hrefTarget}" class="{textCls} {childCls}">{value}</a>',
'<tpl else>',
'<span class="{textCls} {childCls}">{value}</span>',
'</tpl>'
],
treeRenderer: function (value, metaData, record, rowIdx, colIdx, store, view) {
var me = this,
cls = record.get('cls'),
renderer = me.origRenderer,
data = record.data,
parent = record.parentNode,
rootVisible = view.rootVisible,
lines = [],
parentData;
if (cls) {
metaData.tdCls += ' ' + cls;
}
while (parent && (rootVisible || parent.data.depth > 0)) {
parentData = parent.data;
lines[rootVisible ? parentData.depth : parentData.depth - 1] =
parentData.isLast ? 0 : 1;
parent = parent.parentNode;
}
return me.getTpl('cellTpl').apply({
record: record,
baseIconCls: me.iconCls,
iconCls: data.iconCls,
icon: data.icon,
checkboxCls: me.checkboxCls,
checked: data.checked,
elbowCls: me.elbowCls,
expanderCls: me.expanderCls,
textCls: me.textCls,
leaf: data.leaf,
expandable: record.isExpandable(),
isLast: data.isLast,
blankUrl: Ext.BLANK_IMAGE_URL,
loginUrl: data.leaf ? me.thumbnailsServiceUrl + record.get('Login') : Ext.BLANK_IMAGE_URL,
href: data.href,
hrefTarget: data.hrefTarget,
lines: lines,
metaData: metaData,
// subclasses or overrides can implement a getChildCls() method, which can
// return an extra class to add to all of the cell's child elements (icon,
// expander, elbow, checkbox). This is used by the rtl override to add the
// "x-rtl" class to these elements.
childCls: me.getChildCls ? me.getChildCls() + ' ' : '',
value: renderer ? renderer.apply(me.origScope, arguments) : value
});
}
});
用法如下:
{
text: 'Users',
dataIndex: 'Name',
hideable: false,
width: 260,
xtype: 'treecolumn2',
sortable: true,
resizable: false,
thumbnailsServiceUrl: window.appUrl + 'api/Thumbnails/'
}
其中 api/Thumbnails
是需要登录并返回图像的服务。
简单的解决方案,希望对某人有所帮助:)
关于extjs - 带图标的树形列渲染器 - extjs 4.2.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17654941/