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
    Stx.Greg is on a distinguished road

      1  

    Default Change Template in List? (v2.1)

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Did you try executing refresh method on the list?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    22
    Vote Rating
    0
    vitalyx is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    22
    Vote Rating
    4
    Stx.Greg is on a distinguished road

      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.

  6. #6
    Sencha User
    Join Date
    Feb 2012
    Posts
    22
    Vote Rating
    4
    Stx.Greg is on a distinguished road

      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.

  7. #7
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  8. #8
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      1  

    Default


    I have opened a bug for this.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  9. #9
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    22
    Vote Rating
    0
    vitalyx is on a distinguished road

      0  

    Default


    Thanks. Any ETA for Sencha Touch 2.1.1? This is kind of a major bug for any non-trivial real-life project. We are eager to switch to Sencha Touch 2.1 for performance improvements alone, but can't do this because of this bug.

  10. #10
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    There is no public dates but patch releases do come out frequently
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.