Results 1 to 10 of 21

Thread: Change Template in List? (v2.1)

Hybrid View

Previous Post Previous Post   Next Post Next Post
    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-3677 in a recent build.
  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    22
    Vote Rating
    4
      1  

    Default Change Template in List? (v2.1)

    I'm trying to extend the new List component in Sencha Touch 2.1 (I'm using RC2) and I can't seem to change the item template dynamically. I'd like to be able to change item templates by pressing a button, but it won't work. It used to work in version 2.0.1. Is there anything I'm missing?

    Calling setItemTpl() works in the initialize method, but not in edit() or editCompleted() methods.

    Here is the test code I have using.

    Code:
        Ext.application({
            name: 'SenchaTest',
            launch: function () {
    
    
                var app = this;
    
    
                Ext.define('TestModel', {
                    extend: 'Ext.data.Model',
                    config: {
                        fields: [
                            {name: 'field1'},
                            {name: 'field2'},
                            {name: 'field3'},
                        ]
                    }
                });
    
    
                Ext.define('Stx.dataview.MyList', {
                    extend: 'Ext.dataview.List',
    
    
                    config: {
                        normalTpl: null,
                        editTpl: null,
                        editing: false,
                        scrollToTopOnRefresh: false,
                    },
    
    
                    initialize: function () {
                        this.callParent();
                        this.setItemTpl(this.getNormalTpl());
                    },
    
    
                    edit: function () {
                        if (!this.getEditing()) {
                            this.setEditing(true);
                            this.setItemTpl(this.getEditTpl());
                        }
                    },
    
    
                    editCompleted: function () {
                        if (this.getEditing()) {
                            this.setEditing(false);
                            this.setItemTpl(this.getNormalTpl());
                        }
                    },
                });
    
    
                this.store = Ext.create("Ext.data.Store", {
                    model: 'TestModel',
                    data: [
                        {field1: "data1Field1", field2: "data1Field2", field3: "data1Field3"},
                        {field1: "data2Field1", field2: "data2Field2", field3: "data2Field3"},
                        {field1: "data3Field1", field2: "data3Field2", field3: "data3Field3"},
                        {field1: "data4Field1", field2: "data4Field2", field3: "data4Field3"},
                        {field1: "data5Field1", field2: "data5Field2", field3: "data5Field3"},
                        {field1: "data6Field1", field2: "data6Field2", field3: "data6Field3"},
                        {field1: "data7Field1", field2: "data7Field2", field3: "data7Field3"},
                        {field1: "data8Field1", field2: "data8Field2", field3: "data8Field3"},
                        {field1: "data9Field1", field2: "data9Field2", field3: "data9Field3"},
                        {field1: "data10Field1", field2: "data10Field2", field3: "data10Field3"},
                        {field1: "data11Field1", field2: "data11Field2", field3: "data11Field3"},
                        {field1: "data12Field1", field2: "data12Field2", field3: "data12Field3"},
                        {field1: "data13Field1", field2: "data13Field2", field3: "data13Field3"},
                        {field1: "data14Field1", field2: "data14Field2", field3: "data14Field3"},
                        {field1: "data15Field1", field2: "data15Field2", field3: "data15Field3"},
                    ]
                });
    
    
                this.button = Ext.create("Ext.Button", {
                    text: "Edit List",
                    listeners: {
                        tap: function () {
                            if(!app.list.getEditing()) {
                                app.list.edit();
                            } else {
                                app.list.editCompleted();
                            }
                        }
                    }
                });
    
    
                this.normalTpl = Ext.create("Ext.XTemplate", 
                    '{field1}<br/>',
                    '{field2}<br/>',
                    '{field3}',
                {});
    
    
                this.editTpl = Ext.create("Ext.XTemplate", 
                    '{field1}',
                {});
    
    
                this.list = Ext.create("Stx.dataview.MyList", {
                    store: this.store,
                    normalTpl: this.normalTpl,
                    editTpl: this.editTpl,
                    cls: "mylist",
                    flex: 1,
                });
    
    
                this.panel = Ext.create('Ext.Panel', {
                    layout: {type: 'vbox'},
                    padding: 10,
                    style: "background-color: #555555;",
                    items: [
                        this.button,
                        {style: "height: 10px;"},
                        this.list,
                    ],
                });
    
    
                Ext.Viewport.add(this.panel);
            }
    
    
        });

  2. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Vote Rating
    1381
      0  

    Default

    Did you try executing refresh method on the list?
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3
    Sencha - Ext JS Dev Team vitalyx's Avatar
    Join Date
    Jul 2012
    Posts
    42
    Vote Rating
    11
      0  

    Default

    Hi,

    I have the very same issue.

    When using setItemTpl on a list from controller, the list shows empty items. Calling list.refresh() makes no effect.
    But when assigning itemTpl in the view, the list does render the items.
    There was no such behavior in Sencha Touch 2.0.1.

  4. #4
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Vote Rating
    1381
      0  

    Default

    I may have just run into this issue myself. Unless any of you have a simple test case then I will have to take the time to create one today some time.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    22
    Vote Rating
    4
      0  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    I may have just run into this issue myself. Unless any of you have a simple test case then I will have to take the time to create one today some time.
    Is my test code not sufficient? It is just a bare-bones app to demonstrate the problem.

  6. #6
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,050
    Vote Rating
    1381
      0  

    Default

    Quote Originally Posted by Stx.Greg View Post
    Is my test code not sufficient? It is just a bare-bones app to demonstrate the problem.
    It can be simplified:

    Code:
    var store = new Ext.data.Store({
        fields : ['test', 'test2'],
        data   : [
            {
                test  : 'One',
                test2 : 1
            },
            {
                test  : 'Two',
                test2 : 2
            },
            {
                test  : 'Three',
                test2 : 3
            },
            {
                test  : 'Four',
                test2 : 4
            },
            {
                test  : 'Five',
                test2 : 5
            }
        ]
    });
    
    Ext.Viewport.add([
        {
            xtype  : 'toolbar',
            docked : 'top',
            items  : [
                {
                    text    : 'Change itemTpl',
                    handler : function() {
                        var list = Ext.Viewport.child('list');
    
                        list.setItemTpl('{test2}');
                    }
                }
            ]
        },
        {
            xtype   : 'list',
            itemTpl : '{test}',
            store   : store
        }
    ]);
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  7. #7
    Sencha User
    Join Date
    Feb 2012
    Posts
    22
    Vote Rating
    4
      0  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    Did you try executing refresh method on the list?
    Yes, and it didn't work. I forgot to include the refresh statement in my example code, but calling refresh() after calling setItemTpl() has no effect.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •