Hybrid View
-
5 Jan 2007 2:13 PM #1
DomHelper Template using tables (bug in ff & insert at t
DomHelper Template using tables (bug in ff & insert at t
I have 2 issues one seems to be a bug in firefox when using compiled templates and the 2nd is a question of the best way to insert a tr at the top of a table. I am using both the latest copy of yui and yui-ext.
Issue 1:
I am using the YAHOO.ext.DomHelper library to add a tr to a table. I have noticed that there is an exception in firefox when using the following code. If I do not compile teh template it works fine.
The error isCode:<script> var id = 3; function addProfile() { var tplNode = document.getElementById('profile-template'); var tpl = new YAHOO.ext.DomHelper.Template(tplNode.innerHTML); tpl.compile(); tpl.append('profile-table', {profilename: 'My Profile', id: id}); id++ } </script> <input type="button" onClick="addProfile();" value="Add a Profile"> <table> <tbody id="profile-table"> <tr id="profile1"><td>Profile 1</td></tr> <tr id="profile2"><td>Profile 2</td></tr> </tbody> </table> <div style="display:none" id="profile-template"> <tr id="profile{id}"> <td>{profilename} {id}</td> </tr> </div>
Error: unterminated string literal
Source File: Desktop/test/javascripts/yahoo/yui-ext.js
Line: 183, Column: 42
Source Code:
this.compiled = function(values){ return ['
Issue 2:
I noticed that I needed to explicitly define a tbody tag and give it an id to get things to work (instead of giving an id to the table). My question is what is the best way to insert a tr at the top of the table. insertAfter will actually insert it after the tbody tag and of course it doesn't render. append will add it successfully to the end of the table.
-
5 Jan 2007 2:18 PM #2Sencha - Desktop Packager Dev Team
- Join Date
- Mar 2007
- Location
- Baltimore, MD.
- Posts
- 1,745
- Vote Rating
- 5
remove newlines from your div...the template should be all on one line.
Jack, can we fix this? :-)
-
5 Jan 2007 3:50 PM #3Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
My best advice is to wait till Jack releases his new MasterTemplate class wich will enable you to do these kind of things alot easier!
It will be released in the svn pretty soon i guess.
-
5 Jan 2007 8:45 PM #4
thx for the quick response
thx for the quick response
Jarred -
Thanks for the quick response on the newlines in the template html. This fixes the firefox compilation issue. It also fixes the same issue in the latest version of Opera.
Aaron
Does anyone have any ideas on the easiest way to insertRow(0) other than retrieving the top most row id and using 'insertBefore'?
-
6 Jan 2007 6:49 AM #5
The new lines problem with compile is corrected locally, as are single quotes.
To insert the row, use insertBefore with the tbody's first child.
-
6 Jan 2007 7:38 AM #6
attempted yet failed
attempted yet failed
This my attempt yet failure at doing this.... IE throws an error with an invalid pointer and ff says that getAttribute is not a method.Code:<script> var id = 3; function addProfile() { var tplNode = document.getElementById('profile-template'); var table = document.getElementById('profile-table'); var tpl = new YAHOO.ext.DomHelper.Template(tplNode.innerHTML); tpl.compile(); if (table.childNodes[0]) { var firstTRID = table.childNodes[0].getAttribute('id'); tpl.insertBefore(firstTRID, {profilename: 'My Profile', id: id}); } else { tpl.append('profile-table', {profilename: 'My Profile', id: id}); } id++; } </script>
-
6 Jan 2007 7:58 AM #7
First child of the table probably won't be a tr. It could be the tbody, but in your case is likely to be a character node - I guess you have a line end after the "<table>" tag - that's preserved in the DOM.
A Character Node is not an Element, and so will not have getAttribute.
Bookmark this: http://www.w3.org/TR/DOM-Level-2-Cor...t-binding.html
And use Firebug's "HTML" view to familiarize yourself with the structure of your document.
-
6 Jan 2007 3:40 PM #8
-
6 Jan 2007 6:11 PM #9
I tried this and seem to be doing something wrong again...
IE gives me an invalid pointer exception when it uses insertBefore and FF & Opera seem to just be putting HTML onto the page and not putting it in an actual TR. Any ideas?Code:<script> var id = 3; function addProfile() { var tplNode = document.getElementById('profile-template'); var table = document.getElementById('profile-table'); var tpl = new YAHOO.ext.DomHelper.Template(tplNode.innerHTML); if (table.rows[0]) { var firstTRID = table.rows[0].getAttribute('id'); tpl.insertBefore(firstTRID, {profilename: 'My Profile', id: id}); } else { tpl.append('profile-table', {profilename: 'My Profile', id: id}); } id++; } </script>
-
6 Jan 2007 8:07 PM #10
The id isn't required. I think your problem is going to be the way you are doing your template. No browser is going allow a <tr> element to be sitting by itself in a div. They either going to wrap it in a table or throw it away, which means your template is going to bomb either way. Instead of a div, try using a textarea with display none and create the template from it's value.Code:function addProfile() { var tplNode = document.getElementById('profile-template'); var table = document.getElementById('profile-table'); var tpl = new YAHOO.ext.DomHelper.Template(tplNode.innerHTML); if (table.rows[0]) { tpl.insertBefore(table.rows[0], {profilename: 'My Profile', id: id}); } else { tpl.append('profile-table', {profilename: 'My Profile', id: id}); } id++; }
Similar Threads
-
Ext.DomHelper.Template: one template, ten YUI grids
By moraes in forum Community DiscussionReplies: 11Last Post: 18 Dec 2012, 4:55 AM -
Ext Template to insert DOM nodes rather than strings?
By SteveEisner in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 21 Mar 2007, 4:47 PM -
Ext.DomHelper.Template or Ext.Template?
By mystix in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 1 Mar 2007, 3:05 PM -
Help with DomHelper & Tables
By tony.summerville in forum Ext 1.x: Help & DiscussionReplies: 1Last Post: 12 Jan 2007, 5:58 AM -
0.33 beta 3 DomHelper fails to insert html with IE
By moedusa in forum Ext 1.x: Help & DiscussionReplies: 3Last Post: 8 Nov 2006, 4:58 AM


Reply With Quote
