PDA

View Full Version : How to call a store from controller



Jeet Chatterjee
7 May 2013, 4:41 AM
I have a function in my controller, i want to create an instance of store within that function ,and in store i have an Ajax call function to call Servlet .How can i create the instance and call the Ajax from controller .
This is my controller


Ext.define('Gamma.controller.ControlFile', { extend : 'Ext.app.Controller', //define the storesstores : ['BarColumn','RadarView','VoiceCallStore','SMSCallStore','MMSCallStore','GPRSUsageStore'],//define the models models : ['BarCol','radar','VoiceCallModel','SMSCallModel','MMSCallModel','GPRSUsageModel'],//define the viewsviews : ['BarColumnChart','LineChart','RadarChart','VoicePie','SMSPie','MMSPie','GPRSPie'],initializedEvents: false,init: function() { this.control({ '#barColumnChart': { afterlayout: this.afterChartLayout } });},afterChartLayout: function(){ var me=this; if(this.initializedEvents==true) return; this.initializedEvents=true; Ext.getCmp('barColumnChart').series.items[0].on('itemmousedown',function(obj){ var barData=obj.storeItem.data['source']+ ' &' + obj.storeItem.data['count']; me.dataBaseCall(barData); });},dataBaseCall: function(barData){ var bar=getStore('BarColumn'); //here I want to call the ajax}});
and this is my store ........


Ext.define('Gamma.store.BarColumn', {extend: 'Ext.data.Store',model: 'Gamma.model.BarCol',autoLoad: true,pageSize: 100, proxy: { type: 'ajax', url: '../TopCount', //this my servlet name reader: { type: 'json', root: 'topList', totalProperty: 'totalCount', successProperty: 'success' }}});

slemmon
8 May 2013, 8:14 PM
When you have a store in the stores array of a controller an instance of that store is created when the controller is initialized. It will have a storeId of whatever the class name is (for example: the store ID would be 'BarColumn' in this case). You can get a reference to the store using Ext.getStore('BarColumn').

Also, it's helpful if you'll post your code examples in code brackets [ ] and have it formatted with spacing so that it's easier to read. You're more likely to get community participation with easily readable code examples.

uzair.sheikh
30 Jun 2013, 11:49 AM
First save the store in a variable (called referencing as well)
var patientsStore = Ext.getStore('Patients');

And then use patientsStore variable which now refers to Patients Store. E.g. to clear a filter on Patients store:
patientsStore.clearFilter();

And to pass a value to store filter (lets say, user enters a value in a field to filter store results):
patientsStore.filter('PatientID',searchValue);

Where searchValue is textfield.getValue()

asankaub
1 Jul 2013, 3:52 AM
you can get the Store by,


var summaryDataStore = this.getStore('ActivitySummaries');