-
3 Aug 2012 7:03 PM #1
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.
-
Best Answer Posted by mitchellsimoens
This code:
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('Ext.MyList', { xtype: 'myList', config:{ itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>', store: store, 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: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 } });
Code:store : { model : 'myproject.model.Foo' }
-
4 Aug 2012 6:14 AM #2
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:
But before you need to create this list with Ext.defineCode:tems: [ { xtype: 'homepanel' }, { xtype: 'myList' }
Do not forget also too define your tabbar layout correctly - as fit for ex.Code:Ext.define('Ext.MyList', { xtype: 'myList', config:{ itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>', store: store, grouped: true } });
And, last thing, add your myList to app.js
-
6 Aug 2012 5:33 AM #3Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,581
- Vote Rating
- 433
- Answers
- 3100
This code:
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('Ext.MyList', { xtype: 'myList', config:{ itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>', store: store, 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: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 } });
Code:store : { model : 'myproject.model.Foo' }Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
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 almost in print!
When posting code, please use BBCode's CODE tags.
-
7 Aug 2012 10:53 AM #4
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


Reply With Quote