1. #1
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Question 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:

    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;
            }
        }
    into the tpl field in Designer, without it wrapping the member functions in apostrophe's?

    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>

  2. #2
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Default


    Was sure:

    Code:
    <tpl if="[new Date(values.diary) > new Date()]"><span class="column-red">{diary:date("d/m/Y")}</span></tpl>
    was going to work but it doesn't...(always evaluates to red)

    If I do this (very dirty, purists look away now):

    Code:
    <tpl if="alert([new Date(values.diary) < new Date()])"><span class="column-red">{diary:date("d/m/Y")}</span></tpl>
    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)
    Last edited by DrZog; 5 Mar 2011 at 2:38 PM. Reason: Update

  3. #3
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Question


    This works but don't know why the fm alias doesn't work:

    Code:
    <tpl if="diary &lt; today"><span class="column-red">{diary:date("d/m/Y")}</span></tpl>
    <tpl if="diary &gt; today && diary &lt; [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 &gt; [Ext.util.Format.date(new Date().add(Date.DAY, 10),'Y-m-d')]"><span class="column-green">{diary:date("d/m/Y")}</span></tpl>
    Damn that's a bit complicated wot

  4. #4
    Sencha - Desktop Packager Dev Team jarrednicholls's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD.
    Posts
    1,745
    Vote Rating
    7
    jarrednicholls will become famous soon enough jarrednicholls will become famous soon enough

      0  

    Default


    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.

  5. #5
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Question


    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.DAY10))){
                            
    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

  6. #6
    Sencha - Desktop Packager Dev Team jarrednicholls's Avatar
    Join Date
    Mar 2007
    Location
    Baltimore, MD.
    Posts
    1,745
    Vote Rating
    7
    jarrednicholls will become famous soon enough jarrednicholls will become famous soon enough

      0  

    Default


    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.

  7. #7
    Ext JS Premium Member DrZog's Avatar
    Join Date
    Mar 2007
    Location
    Bristol, UK
    Posts
    197
    Vote Rating
    1
    DrZog is on a distinguished road

      0  

    Default


    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

  1. Accessing the RowIndex in the template of a templatecolumn
    By radamanth in forum Ext 3.x: Help & Discussion
    Replies: 8
    Last Post: 7 Sep 2010, 4:49 AM
  2. [OPEN] [FIXED][3.0.0] Important bug in Ext.grid.TemplateColumn
    By jthevenoux in forum Ext 3.x: Bugs
    Replies: 5
    Last Post: 19 Mar 2010, 7:21 AM
  3. possible bug in Ext.grid.TemplateColumn
    By stratton in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 16 Sep 2009, 11:55 AM
  4. Replies: 2
    Last Post: 20 Aug 2009, 3:48 AM

Thread Participants: 1

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar