PDA

View Full Version : URGENT HELP : Store not loading



rxbass
23 Nov 2012, 11:06 PM
Hi ,

i need help on reloading the json store with the search data.

By default, it calls json store from


config.store = new GO.data.JsonStore({
url: GO.settings.modules.sms.url+ 'json.php',
baseParams: {task: 'sms_list'},
root: 'results',
id: 'id',
totalProperty:'total',
fields: fields.fields,
remoteSort: true
});


While on searching, it calls the below function and retrieve the results. The problem is, i cant load the values what i have got from search results. Please help on this.




searchLoad : function(vals)
{
Ext.Ajax.request({
url : GO.settings.modules.sms.url + 'json.php',
params : {
'task' : 'search',
'phone_number' : vals.phone_number,
},
waitMsg : GO.lang['waitMsgSave'],
success: function(form,action) {
this.store.reload();
},
failure: function(form,action){
Ext.MessageBox.alert('Error',action.result.data.msg);
this.store.reload();
},
scope:this
});

}

willigogs
24 Nov 2012, 12:39 AM
You need to load the received data into the store - not reload it.

Example:

Ext.Ajax.request({
url: 'ajax_demo/sample.json',
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
store.loadData(obj);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});


http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Ajax-method-request

rxbass
24 Nov 2012, 12:46 AM
responseText is coming, but it's not still loading into the grid. Any idea?

willigogs
24 Nov 2012, 1:00 AM
If you're receiving the responseText object, then I would assume you're not loading the data into the store correctly.

You will obviously have to grab the correct store to load the data into.

E.g

var store = Ext.getCmp('your_store_id');
store.loadData(obj)

I strongly recommend using Firebug and constantly console.log() your variables/objects to check they are populated.

rxbass
24 Nov 2012, 1:41 AM
but my default store values loading from config.store like this below,




config.store = new GO.data.JsonStore({ url: GO.settings.modules.sms.url+ 'json.php', baseParams: {task: 'sms_list'}, root: 'results', id: 'id', totalProperty:'total', fields: fields.fields, remoteSort: true });

my log for 'obj'

Object { results=[0], total=
"0", success=
true}

how to use store id for this config.store?

willigogs
24 Nov 2012, 1:53 AM
Could you provide the code for the object which this config.store belongs to?

Is the searchLoad function also part of this object?

If so, you'd simply have to reference this.store.loadData(obj) :)

rxbass
24 Nov 2012, 2:20 AM
GO.sms.SmsGrid = function(config){


if(!config)
{
config = {};
}

config.paging=true;
config.border=false;

var fields ={
fields : ['id','date','phone_number','message','status','company_id','price'],
columns : [
{
header: 'Date',
dataIndex: 'date'
},
{
header: 'Phone Number',
dataIndex: 'phone_number'
},
{
header: 'Message',
dataIndex: 'message',
},
{
header: 'Message Status',
dataIndex: 'status',
},
{
header: 'Company Id',
dataIndex: 'company_id',
},
{
header: 'Price',
dataIndex: 'price',
}
]
}


config.store = new GO.data.JsonStore({
url: GO.settings.modules.sms.url+ 'json.php',
baseParams: {task: 'sms_list'},
root: 'results',
id: 'id',
totalProperty:'total',
fields: fields.fields,
remoteSort: true
});

var contactsColumnModel = new Ext.grid.ColumnModel(fields.columns);
contactsColumnModel.defaultSortable = true;
config.cm=contactsColumnModel;

config.view=new Ext.grid.GridView({
autoFill: true,
forceFit: true,
emptyText: GO.lang.strNoItems
}),
config.sm=new Ext.grid.RowSelectionModel();
config.loadMask=true;

config.enableDragDrop=true;
config.ddGroup='AddressBooksDD';

GO.sms.SmsGrid.superclass.constructor.call(this, config);
};




Ext.extend(GO.sms.SmsGrid, GO.grid.GridPanel, {

loaded : false,

afterRender : function()
{
GO.sms.SmsGrid.superclass.afterRender.call(this);

if(this.isVisible())
{
this.onGridShow();
}
},
onGridShow : function(vals)
{
if(!this.loaded && this.rendered)
{
this.store.load();
this.loaded=true;
}
},
searchLoad : function(vals)
{
Ext.Ajax.request({
url : GO.settings.modules.sms.url + 'json.php',
params : {
'task' : 'search',
'phone_number' : vals.phone_number,
},
success: function(response, opts) {


var obj = Ext.decode(response.responseText);
console.log(obj);
this.store.loadData(obj);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
},
scope:this
});

}
});




Please check this..

willigogs
24 Nov 2012, 2:48 AM
I imagine it will be:

GO.sms.SmsGrid.store.loadData(obj)

If this doesn't work, I'll take a better look once I'm at my computer later...

rxbass
24 Nov 2012, 3:08 AM
No.. not working.. and thanks for your help :) ... me also try to sort out this today..

willigogs
24 Nov 2012, 7:41 AM
Not able to look at it right now - but the issue will be because you're not grabbing the store to load the data into.

Try to grab the store, and then check you have it by using console.log().

Once you are sure you are able to correctly reach the store, THEN load the data into it.

Start by performing a "console.log(GO.sms.SmsGrid)" within your searchLoad function.