-
21 Jun 2012 6:52 AM #1
Unanswered: Store updates, but dataview doesn't until I refresh page
Unanswered: Store updates, but dataview doesn't until I refresh page
Hello World

I have a tabpanel with 3 panels: dataview (Schedule), form (Settings) & panel (About). When the user updates his/her Settings, the store is updated/filtered accordingly. The store is tied to the dataview. Problem is that I need to explicitly refresh the page (click browser's refresh) in order to display the new filtered data. Could someone please assist? I'm not sure where I'm going wrong here.
Store ..
Code:Ext.define('MyApp.store.Movies', { extend: 'Ext.data.Store', config: { model: 'MyApp.model.Movie', autoLoad: true, proxy: { type: 'ajax', url: 'data/json', reader: { type: 'json', rootProperty: 'MovieSchedule' } }, // timedout: 1000, listeners: { // exception: function() { // console.log('we are offline'); // }, load: function() { var since; var bouquet; var rated; var offline = Ext.getStore('MoviesOffline'); var userstore = Ext.getStore('User'); userstore.each(function(record) { since = record.get('since'); bouquet = record.get('bouquet'); rated = record.get('rated'); }); console.log('we\'re looking for ' + since + ', ' + bouquet + ' and ' + rated); offline.filter([ { // Bouquet filter property: 'bouquets', value: bouquet, anyMatch: true, caseSensitive: true }, { // Movies made since filter filterFn: function(item) { return item.data.release_date >= since; } }, { // Movies rated at least filter filterFn: function(item) { return item.data.score >= rated; } } ]); offline.load(); this.each(function(record) { offline.add(record.data); }); offline.sync(); console.log('Updated: Offline store now has ' + offline.getCount() + ' items!'); } } } });Tab panelCode:Ext.define('MyApp.view.Schedule', { extend: 'Ext.Panel', xtype: 'schedule', //id: 'schedule', config: { title: 'Schedule', iconCls: 'bookmarks', fullscreen: true, layout: { type: 'fit' }, items: [ { xtype: 'titlebar', title: 'Schedule', docked: 'top' }, { xtype: 'dataview', padding: '5px', store: 'MoviesOffline', itemTpl: tpl, itemCls: 'movie-entry', style: { background: 'black' } } ] } });
Code:xt.define('MyApp.view.Main', { extend: 'Ext.tab.Panel', xtype: 'main', requires: [ 'MyApp.view.About', 'MyApp.view.Welcome' ], config: { itemId: 'main', fullscreen: true, tabBarPosition: 'bottom', items: [ { xtype: 'schedule', listeners: { // or activate? show: function() { console.log('Schedule now active ..'); //Ext.getCmp('dataview').refresh() } } }, { xtype: 'settings' } ] }, // this section selects the 3rd tab panel initialize: function() { main = this; App.getCorrectPanel(); main.callParent(arguments); } });
-
24 Jun 2012 1:40 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
Two things...
You shouldn't use the fullscreen config for child items.
You are creating a global variable 'main' in your tab panel. Add 'var ' before it.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.
-
25 Jun 2012 1:46 AM #3
Hi Mitchell
Thank you for your response (really appreciated)...also been reading this link
Just a note that changingmain = this;tovar main = this;results in the following error: "Uncaught ReferenceError: main is not defined"
That said, I know that my dataview is tied to my store (data is being displayed), the problem though is that when the store is filtered, the dataview doesn't get updated. I need to refresh the browser in order to get the new filtered data displaying. Any ideas?
-
25 Jun 2012 5:10 AM #4
Anyone?
Anyone?
Ideas, suggestions - greatly appreciated

-
25 Jun 2012 5:23 AM #5
Riyaad,
Are you using the reference to "main" anywhere else in your project, and expecting the same object? By addingyou scope it locally to the function (naturally this denies it from other scopes).Code:var main = this;
-
25 Jun 2012 5:35 AM #6
Hi Robert,
I am, in (bold below)
But I doubt that's the issue though, I'm trying to programatically update my dataview when I click back to my schedule tab. Currently I need to manually refresh the page so the my dataview can read the updated store.Code:Ext.application({ name: 'MyApp', models: [ 'Movie', 'Bouquet', 'Rated', 'Since', 'User' ], views: [ 'Main', 'Schedule', 'Movies', 'Settings', 'Form', 'Details' ], controllers: [ 'Details', 'Settings' ], stores: [ 'Movies', 'MoviesOffline', 'Bouquet', 'Rated', 'Since', 'User' ], launch: function(){ Ext.create('MyApp.view.Main'); } }); App = function(){ return { getCorrectPanel: function(){ console.log('We trying to ...'); var userStore = Ext.getStore('User'); var count = userStore.getCount(); userStore.each(function(record){ console.log(record.get('bouquet')); console.log(record.get('rated')); console.log(record.get('age')); console.log(record.get('gender')); console.log(record.get('since')); }) console.log('count is: ' + count); if (count == 0){ console.log('Show the Welcome Panel'); main.add(Ext.create('MyApp.view.Welcome')); main.getTabBar().getComponent(1).setBadgeText('1'); main.setActiveItem(2); } else { console.log('Show the About Panel'); main.add(Ext.create('MyApp.view.About')); } } }; }();
-
25 Jun 2012 6:11 AM #7
Riyaad, this issue is because you're not making a controller for this functionality: a controller is where this stuff belongs. You should not have to update the page so that the DataView refreshes itself, it's bound to the store object (if you pass it the store) so that it updates itself.
And to refresh a DataView, if it must be done manually, just call refresh.Code:Ext.define('MyApp.controller.Main', { extend : 'Ext.app.Controller', refs: { view: 'main' }, initialize: function() { this.callParent(arguments); var view = this.getView(); view.getTabBar().getComponent(1).setBadgeText('1'); view.setActiveItem(2); // ... } });Last edited by mitchellsimoens; 25 Jun 2012 at 6:13 AM. Reason: edited code to add red code
-
25 Jun 2012 6:14 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
^^added red code to extend Controller
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.
-
25 Jun 2012 6:55 AM #9
Thank you both - will have to refractor some code to get this working and post the solution when done.
Appreciated ...
-
27 Jun 2012 12:41 AM #10
Okay so I've
Okay so I've
added the main controller as
in my main view I have...Code:Ext.define('MyApp.controller.Main', { extend: 'Ext.app.Controller', store: 'MyApp.store.User', config: { refs: { view: 'main' } }, initialize: function() { console.log('Init main controller'); this.callParents(arguments); var main_view = this.getView(); console.log('We need to ...'); var userStore = Ext.getStore('User'); var count = userStore.getCount(); userStore.each(function(record){ console.log(record.get('bouquet')); console.log(record.get('rated')); console.log(record.get('age')); console.log(record.get('gender')); console.log(record.get('since')); }); console.log('count is: ' + count); if (count == 0) { console.log('Show the Welcome Panel'); main_view.add(Ext.create('MyApp.view.Welcome')); main_view.getTabBar().getComponent(1).setBadgeText('1'); main_view.setActiveItem(2); } else { console.log('Show the About Panel'); main_view.add(Ext.create('MyApp.view.About')); } } });
Code:Ext.define('MyApp.view.Main', { extend: 'Ext.tab.Panel', xtype: 'main', id: 'main', requires: [ 'MyApp.view.About', 'MyApp.view.Welcome' ], config: { //itemId: 'main', fullscreen: true, tabBarPosition: 'bottom', items: [ { xtype: 'schedule', listeners: { show: function() { console.log('Schedule now active ..'); } } }, { xtype: 'settings' } ] }, });
In app I have ...
Problem: the main controller doesn't fire up ...Code:controllers: [ 'Main', 'Details', 'Settings' ],
Why does my initialize not fire up?


Reply With Quote