1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    8
    Vote Rating
    0
    amritsharma is on a distinguished road

      0  

    Default Answered: DataView List inside a TabPanel -- Quick Question

    Answered: DataView List inside a TabPanel -- Quick Question


    I have a simple Tab Panel to test how to add a DataView list inside one of those tabs.

    This is my TabPanel -- nothing fancy, just 2 tabs. I want the DataView list in the 'testpanel' tab.

    Ext.define("myproject.view.Main", {
    extend: 'Ext.tab.Panel',


    requires: [
    'Ext.TitleBar',
    ],

    config: {
    tabBarPosition: 'bottom',


    items: [
    {
    xtype: 'homepanel'
    },
    {
    xtype: 'testpanel'
    }
    ]
    }
    });

    For the DataView List, I used the exact code from Sencha Docs example:
    http://docs.sencha.com/touch/2-0/#!/....dataview.List


    I just added this code to the Test.js in /app/view/Test.js. Again, this is just exactly taken from the example.


    Ext.define('Contact', {
    extend: 'Ext.data.Model',
    config: {
    fields: ['firstName', 'lastName']
    }
    });


    var store = Ext.create('Ext.data.Store', {
    model: 'Contact',
    sorters: 'lastName',


    grouper: {
    groupFn: function(record) {
    return record.get('lastName')[0];
    }
    },


    data: [
    { firstName: 'Tommy', lastName: 'Maintz' },
    { firstName: 'Rob', lastName: 'Dougan' },
    { firstName: 'Ed', lastName: 'Spencer' },
    { firstName: 'Jamie', lastName: 'Avins' },
    { firstName: 'Aaron', lastName: 'Conran' },
    { firstName: 'Dave', lastName: 'Kaneda' },
    { firstName: 'Jacky', lastName: 'Nguyen' },
    { firstName: 'Abraham', lastName: 'Elias' },
    { firstName: 'Jay', lastName: 'Robinson'},
    { firstName: 'Nigel', lastName: 'White' },
    { firstName: 'Don', lastName: 'Griffin' },
    { firstName: 'Nico', lastName: 'Ferrero' },
    { firstName: 'Jason', lastName: 'Johnston'}
    ]
    });


    Ext.create('Ext.List', {
    fullscreen: true,
    itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
    store: store,
    grouped: true
    });

    Question
    How on earth do I make this List to just appear inside one of the tab panels? Currently it takes over the entire Sencha application, and I don't see the TabPanel interface. All is see is this List of data.

  2. This code:

    Code:
    Ext.define('Ext.MyList', {
    xtype: 'myList',
    config:{
    itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
    store: store,
    grouped: true
    }
    });
    Is NOT complete and not 100% recommended. You shouldn't use the Ext namespace for your app class names, you don't have an extend property and you shouldn't use an instance in the config like you are the store:

    Code:
    Ext.define('myproject.view.MyList', {
        extend : 'Ext.dataview.List',
        xtype: 'myList',
    
        config:{
            itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
            store: 'store-id',
            grouped: true
        }
    });
    The store config can take a few different values. If it's a string it will try to find that store via the store id. Or you can use a config object:

    Code:
    store : {
        model : 'myproject.model.Foo'
    }

  3. #2
    Sencha User
    Join Date
    Mar 2012
    Posts
    106
    Answers
    5
    Vote Rating
    5
    lgertel is on a distinguished road

      1  

    Default


    Inside your home panel or inside your testpanel you have to add it an item.
    You should not use Ext.create outside a controller, so you can do this:

    Code:
    tems: [
    {
    xtype: 'homepanel'
    },
    {
    xtype: 'myList'
    } 
    But before you need to create this list with Ext.define
    Code:
    Ext.define('Ext.MyList', {
    xtype: 'myList',
    config:{
    itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
    store: store,
    grouped: true
    }
    });
    Do not forget also too define your tabbar layout correctly - as fit for ex.
    And, last thing, add your myList to app.js

  4. #3
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,649
    Answers
    3454
    Vote Rating
    817
    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

      2  

    Default


    This code:

    Code:
    Ext.define('Ext.MyList', {
    xtype: 'myList',
    config:{
    itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
    store: store,
    grouped: true
    }
    });
    Is NOT complete and not 100% recommended. You shouldn't use the Ext namespace for your app class names, you don't have an extend property and you shouldn't use an instance in the config like you are the store:

    Code:
    Ext.define('myproject.view.MyList', {
        extend : 'Ext.dataview.List',
        xtype: 'myList',
    
        config:{
            itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
            store: 'store-id',
            grouped: true
        }
    });
    The store config can take a few different values. If it's a string it will try to find that store via the store id. Or you can use a config object:

    Code:
    store : {
        model : 'myproject.model.Foo'
    }
    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. #4
    Sencha User
    Join Date
    Aug 2012
    Posts
    8
    Vote Rating
    0
    amritsharma is on a distinguished road

      0  

    Default Thank you gentlemen!

    Thank you gentlemen!


    Thank you Lucas & Mitchell. I finally made it work. You guys got me in the right direction.

    Thanks Mitchell. I started with your code as the base for my tab panel that I wanted to have a List. I had some problem figuring out why the app couldn't find my store even though I made sure I have no typos in my panels. Then, i figured that I had not declared the store and model in my app.js file. Duh! It started to work.

    Now I have a basic list panel working inside the Tab Panel. Thank you!

    Some additional thoughts:
    -- I was initially thinking that I would have to have to extend 'Ext.Panel' first, and then under 'items', I would have to mention that I need a Ext.DataView.List.
    -- But clearly that not how it works.

    I still don't understand all the moving pieces 100% , but I've definitely learned a lot with this simple project.

    Thank you!

    @amrit_sharma