PDA

View Full Version : Template.append doesn't seem to be returning anything, ever



sheynkman
22 Dec 2006, 4:42 AM
I am setting the options "return Element" parameter true on template append. It never seems to return anything, but the text renders just fine.

this.celltempl = new YAHOO.ext.DomHelper.Template('<span class="ygrid-col ygrid-col-{col} {lst}"><span class="ygrid-cell-text">{val}</span></span>');

then, later, after setting values:
newcell = this.celltempl.append(row,{col: colIndex, lst: lst, val: val},true);
if (newcell) {
alert(newcell);
}

never happens.... always null?

tryanDLS
22 Dec 2006, 8:28 AM
Is 'row' a valid HTML element?

jack.slocum
22 Dec 2006, 2:21 PM
There has to be something else wrong. I use this method extensively. Can you show any more code?

sheynkman
22 Dec 2006, 2:29 PM
YAHOO.ext.grid.HMParameterGridView = function() {
YAHOO.ext.grid.HMParameterGridView.superclass.constructor.call(this);
this.celltempl = new YAHOO.ext.DomHelper.Template('<span class="ygrid-col ygrid-col-{col} {lst}"}><span class="ygrid-cell-text">{val}</span></span>');
//this.celltempl.compile();
};
YAHOO.extendX(YAHOO.ext.grid.HMParameterGridView, YAHOO.ext.grid.GridView, {
renderRow: function(dataModel, row, rowIndex, colCount, renderers) {
for(var colIndex = 0; colIndex < colCount; colIndex++){
if ((dataModel.renderers) && dataModel.renderers[rowIndex]){
val = renderers[colIndex](dataModel.getValueAt(rowIndex, colIndex), rowIndex, colIndex);};
if (val === '') {val = ''}
lst = colIndex == colCount-1 ? ' ygrid-col-last' : '';
newcell = this.celltempl.append(getEl(row),{col: colIndex, lst: lst, val: val},true);
if (newcell) {
alert(newcell);
}
}
} etc....

I spared the continuation of the details... but that's it. I do not really mean to have an alert there :), just testing. The point is that everything renders just fine... just no return element.

jack.slocum
22 Dec 2006, 2:43 PM
this.celltempl.append(getEl(row),{col: colIndex, lst: lst, val: val},true);

should be:

this.celltempl.append(row,{col: colIndex, lst: lst, val: val},true);

DomHelper doesn't take YAHOO.ext.Element objects (although it probably should).

sheynkman
23 Dec 2006, 7:44 AM
Of course it should not be getEl... I posted my Nth iteration of hacking this thing.
Still no return if it's

newcell = this.celltempl.append(row,{col: colIndex, lst: lst, val: val},true);


I know you use this function having looked at your code, and in general I am a big fan of yui-ext. So this little thing has me baffled.

tryanDLS
23 Dec 2006, 9:28 AM
Did you try wrapping that call in a try-catch or stepping into w/Firebug? Maybe an exception is being swallowed.

sheynkman
23 Dec 2006, 10:01 AM
try
{
newcell = this.celltempl.append(row,{col: colIndex, lst: lst, val: val},true);
}
catch(err) {
alert(err.description);

}
if (newcell) {
alert(newcell);
}
- No error, no alert, no newcell returned.

jack.slocum
23 Dec 2006, 2:19 PM
I think I know what it is. At the point you are trying to insert, the row has yet to be added to the DOM. It isn't added until after it is rendered. YAHOO.util.Dom (used by DomHelper for lookups) will fail on nodes that are not yet part of the document.