LisburnLad
3 Jan 2012, 1:43 PM
In version 4.0x I was using the Ext.override method to override the Ext.tree.Column class, to allow me to add a background-position style attribute to tree nodes. Using this I was then able to supply the position of an icon in an image sprite, in the record for each tree node. However, the behaviour of Ext.override seems to have changed in version 4.1 (I'm currently using the latest beta) and now, rather than overriding the class, both classes seem to be used. The result of this is that my tree now appears twice - once from the original Ext.tree.Column class and once from my override class.
My override is composed by taking the whole of Column.js (from src\tree) and wrapping it as follows:
Ext.require('Ext.tree.Column', function ()
{
Ext.override(Ext.tree.Column,
{
initComponent: function ()
{
var origRenderer = this.renderer || this.defaultRenderer,
origScope = this.scope || window;
this.renderer = function (value, metaData, record, rowIdx, colIdx,store,view)
{
var buf = [],
format = Ext.String.format,
depth = record.getDepth(),
treePrefix = Ext.baseCSSPrefix + 'tree-',
elbowPrefix = treePrefix + 'elbow-',
expanderCls = treePrefix + 'expander',
imgText = '<img style="background-position:{2};" src="{1}" class="{0}" />',
checkboxText = '<input type="button" role="checkbox" class="{0}" {1} />',
formattedValue = origRenderer.apply(origScope, arguments),
href = record.get('href'),
target = record.get('hrefTarget'),
cls = record.get('cls');
while (record)
{
if (!record.isRoot() || (record.isRoot() && view.rootVisible))
{
if (record.getDepth() === depth)
{
buf.unshift(format(imgText,
treePrefix + 'icon ' +
treePrefix+'icon' +(record.get('icon') ? '-inline ':(record.isLeaf() ? '-leaf ' : '-parent ')) +
(record.get('iconCls') || ''),
record.get('icon') || Ext.BLANK_IMAGE_URL,
record.get('iconPos') || '-1px -1px'
));
....
CONTINUES AS EXACT COPY FROM tree\Column.js
....
The parts of the code shown in red are the additions I've made to the class, to allow the location of the icon in the sprite to be set.
In version 4.0x all of this worked fine - a single tree was drawn and the icon specified by the position in the sprite was added as the tree node icon.
Now, in version 4.1, when the tree is being drawn, for some reason the original Ext.tree.Column class is called. This creates the nodes for the tree without the background-position attribute. However, when it reaches the line equivalent to the line shown in green above, it then calls the 'renderer' function in the override class and at this point my code gets run. This results in my markup for the tree icons being loaded into 'formattedValue', which is normally used to supply the tree node's text, and so 2 icons appear for each tree node. The result of this is shown in the attached image. The parts of the tree on the left come from the original class and those on the right from the overriding class.
30434
Would anyone know why this behaviour is now happening in version 4.1 (does it represent a bug in the Ext.override function?) or of any possible work-arounds, or altenative methods I could use to set the background position for the sprite into the tree node markup.
Thanks for any help.
Regards,
Steve
My override is composed by taking the whole of Column.js (from src\tree) and wrapping it as follows:
Ext.require('Ext.tree.Column', function ()
{
Ext.override(Ext.tree.Column,
{
initComponent: function ()
{
var origRenderer = this.renderer || this.defaultRenderer,
origScope = this.scope || window;
this.renderer = function (value, metaData, record, rowIdx, colIdx,store,view)
{
var buf = [],
format = Ext.String.format,
depth = record.getDepth(),
treePrefix = Ext.baseCSSPrefix + 'tree-',
elbowPrefix = treePrefix + 'elbow-',
expanderCls = treePrefix + 'expander',
imgText = '<img style="background-position:{2};" src="{1}" class="{0}" />',
checkboxText = '<input type="button" role="checkbox" class="{0}" {1} />',
formattedValue = origRenderer.apply(origScope, arguments),
href = record.get('href'),
target = record.get('hrefTarget'),
cls = record.get('cls');
while (record)
{
if (!record.isRoot() || (record.isRoot() && view.rootVisible))
{
if (record.getDepth() === depth)
{
buf.unshift(format(imgText,
treePrefix + 'icon ' +
treePrefix+'icon' +(record.get('icon') ? '-inline ':(record.isLeaf() ? '-leaf ' : '-parent ')) +
(record.get('iconCls') || ''),
record.get('icon') || Ext.BLANK_IMAGE_URL,
record.get('iconPos') || '-1px -1px'
));
....
CONTINUES AS EXACT COPY FROM tree\Column.js
....
The parts of the code shown in red are the additions I've made to the class, to allow the location of the icon in the sprite to be set.
In version 4.0x all of this worked fine - a single tree was drawn and the icon specified by the position in the sprite was added as the tree node icon.
Now, in version 4.1, when the tree is being drawn, for some reason the original Ext.tree.Column class is called. This creates the nodes for the tree without the background-position attribute. However, when it reaches the line equivalent to the line shown in green above, it then calls the 'renderer' function in the override class and at this point my code gets run. This results in my markup for the tree icons being loaded into 'formattedValue', which is normally used to supply the tree node's text, and so 2 icons appear for each tree node. The result of this is shown in the attached image. The parts of the tree on the left come from the original class and those on the right from the overriding class.
30434
Would anyone know why this behaviour is now happening in version 4.1 (does it represent a bug in the Ext.override function?) or of any possible work-arounds, or altenative methods I could use to set the background position for the sprite into the tree node markup.
Thanks for any help.
Regards,
Steve