-
5 Mar 2011 1:08 PM #1
Creating XTemplates in Grid TemplateColumn
Creating XTemplates in Grid TemplateColumn
I'm inserting XTemplate definitions into the tpl config field in Designer (EXT.grid.TemplateColumn). How do you insert template member functions such as:
into the tpl field in Designer, without it wrapping the member functions in apostrophe's?Code:'<p>Name: {name}</p>', '<p>Kids: ', '<tpl for="kids">', '<tpl if="this.isGirl(name)">', '<p>Girl: {name} - {age}</p>', '</tpl>', // use opposite if statement to simulate 'else' processing: '<tpl if="this.isGirl(name) == false">', '<p>Boy: {name} - {age}</p>', '</tpl>', '<tpl if="this.isBaby(age)">', '<p>{name} is a baby!</p>', '</tpl>', '</tpl></p>', { // XTemplate configuration: compiled: true, disableFormats: true, // member functions: isGirl: function(name){ return name == 'Sara Grace'; }, isBaby: function(age){ return age < 1; } }
On the same subject, why doesn't this work?
Code:<tpl if="diary > new Date().add(Date.DAY, 10)"><span class="column-green">{diary:date("d/m/Y")}</span></tpl> <tpl if="diary < new Date()"><span class="column-red">{diary:date("d/m/Y")}</span></tpl>
-
5 Mar 2011 2:32 PM #2
Was sure:
was going to work but it doesn't...(always evaluates to red)Code:<tpl if="[new Date(values.diary) > new Date()]"><span class="column-red">{diary:date("d/m/Y")}</span></tpl>
If I do this (very dirty, purists look away now):
I can see that the date comparisons are working but the (false, flase, true on my data) all columns are red when it should just be the last)Code:<tpl if="alert([new Date(values.diary) < new Date()])"><span class="column-red">{diary:date("d/m/Y")}</span></tpl>Last edited by DrZog; 5 Mar 2011 at 2:38 PM. Reason: Update
-
5 Mar 2011 3:34 PM #3
This works but don't know why the fm alias doesn't work:
Damn that's a bit complicated wotCode:<tpl if="diary < today"><span class="column-red">{diary:date("d/m/Y")}</span></tpl> <tpl if="diary > today && diary < [Ext.util.Format.date(new Date().add(Date.DAY, 10),'Y-m-d')]"><span class="column-orange">{diary:date("d/m/Y")}</span></tpl> <tpl if="diary > [Ext.util.Format.date(new Date().add(Date.DAY, 10),'Y-m-d')]"><span class="column-green">{diary:date("d/m/Y")}</span></tpl>
-
7 Mar 2011 6:14 AM #4Sencha - Desktop Packager Dev Team
- Join Date
- Mar 2007
- Location
- Baltimore, MD.
- Posts
- 1,745
- Vote Rating
- 5
Yeah the last sample will work. In 3.x, escaping angle brackets within an if="" statement is necessary. I believe that's no longer necessary in 4.0.
Yeah "fm" doesn't appear to actually be included ever. Docs are outdated. The preferred way is by affixing ":<fm_func>" to the end of a variable name - however that only works for formatting variables with a reference. E.g., (new Date()):date('') wouldn't work. Might be worth posting on the forums as a feature request.
-
12 Mar 2011 1:44 PM #5
Hmmm, maybe I'm missing something but how do I get something like this to work in designer then (or is it not possible?)
PHP Code:<tpl>
{[this.dateTest(values)]},
{ dateTest : function(diary){
var diaryDate,
doDiary = Date.parseDate(diary, 'Y-m-d'),
doToday = new Date();
if (doDiary <= doToday){
diaryDate = '<span class="column-red">'+Ext.util.Format.date(diary,'d/m/Y')+'</span>';
} else if ((doDiary > doToday) && (doDiary <= doToday.add(Date.DAY, 10))){
diaryDate = '<span class="column-orange">'+Ext.util.Format.date(diary,'d/m/Y')+'</span>';
} else if (doDiary > doToday){
diaryDate = '<span class="column-green">'+Ext.util.Format.date(diary,'d/m/Y')+'</span>';
}
return diaryDate
}
}
</tpl>
Cheers
Roland
-
12 Mar 2011 7:29 PM #6Sencha - Desktop Packager Dev Team
- Join Date
- Mar 2007
- Location
- Baltimore, MD.
- Posts
- 1,745
- Vote Rating
- 5
This isn't possible, because the Designer won't allow you to supply a function. We're going to be doing work on Template Management that will support this handy feature of XTemplates. If you absolutely need to augment your XTemplates with instance methods, you should define and use the XTemplate in your implementation (.js) file(s) directly, and not worry about configuring it in the Designer. This will be improved for sure.
-
13 Mar 2011 12:16 AM #7
OK thanks, good to know. I actually just changed the column back to a grid column in designer and then set a renderer in the implementation file....
Similar Threads
-
Accessing the RowIndex in the template of a templatecolumn
By radamanth in forum Ext 3.x: Help & DiscussionReplies: 8Last Post: 7 Sep 2010, 4:49 AM -
[OPEN] [FIXED][3.0.0] Important bug in Ext.grid.TemplateColumn
By jthevenoux in forum Ext 3.x: BugsReplies: 5Last Post: 19 Mar 2010, 7:21 AM -
possible bug in Ext.grid.TemplateColumn
By stratton in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 16 Sep 2009, 11:55 AM -
[CLOSED][3.0.0] Ext.grid.TemplateColumn - Artefact in constructor
By BitPoet in forum Ext 3.x: BugsReplies: 2Last Post: 20 Aug 2009, 3:48 AM


Reply With Quote