PDA

View Full Version : Reload a store from a grid



crashT
7 Mar 2011, 8:21 AM
Hi,
I am just trying to project its own ExtJS.
I currently have the problem that I want the grid and the store of the grid reload or refresh after saving.

I can not find the right code to function in the success of the ajax requests to reload the grid or the store.

Hallo,
ich versuche mich gerade an einem eigenen extJS Projekt.
Im Moment habe ich das Problem, das ich das Grid bzw. den Store des Grids nach dem Speichern reloaden bzw. refreshen will.

Ich finde nicht den richtigen Code um in der success Funktion des AjaxRequests das Grid bzw. den store zu reloaden.

Hier ist der Code:

<script type="text/javascript">
Ext.ns('Test.FinderAdmin');
(function(){

var Grid = Ext.extend(Ext.grid.EditorGridPanel, {
title: 'Attribute der Kategorie', // Bezeichnung
id: 'Grid',
stripeRows:true, // Zeilen unterschiedlich einfaerben
region: 'center',
boxMinHeight: 200,
autoHeight: true,
initComponent: function() {
/*
Datenquelle definieren
*/
this.store = new Ext.data.Store({
url: '{url action=getAttributes}',
autoLoad: true,
storeId: 'attributesStore',
reader: new Ext.data.JsonReader({
root: 'data',
totalProperty: 'count',

fields: [
'id','attr_id','name','categoryID','state'
]
})
});
/*
Spalten definieren
*/
this.columns = [
{
xtype: 'gridcolumn',
dataIndex: 'id',
header: 'ID',
sortable: false,
width: 40,
hidden: false
},
{
xtype: 'gridcolumn',
dataIndex: 'attr_id',
header: 'AttributeID',
sortable: false,
width: 70,
hidden: false
},
{
xtype: 'gridcolumn',
dataIndex: 'categoryID',
header: 'CategoryID',
sortable: false,
width: 70,
hidden: false
},
{
xtype: 'gridcolumn',
dataIndex: 'name',
header: 'Bezeichnung',
sortable: false,
width: 250
},
{
xtype: 'gridcolumn',
dataIndex: 'state',
header: 'Status',
sortable: false,
width: 150,
editor: {
xtype: "combo",
typeAhead: true,
triggerAction:"all",
lazyRender: true,
listClass: "x-combo-list-small",
store:[
[ "0" , "Nicht anzeigen" ], //the value at index 0 is
//assumed to be the combo value
[ "1" , "Dropdown" ], //the value at index 1 is
//assumed to be the combo text
[ "2" , "Slider" ],

[ "3" , "Boxen" ]
]
}
}
];

this.buttons = [{
text: 'Speichern',
handler: function(){
var data = [];
Ext.each(this.getStore().getModifiedRecords(),
function(record){
data.push(record.data);
});
Ext.Ajax.request({
url: '{url module=backend controller=FinderAdmin action=setAttributes}',
params: { data: Ext.encode(data)},
success: function(){
/*if(success == true){
Ext.Msg.alert('Insert/Update','Daten sind angekommen');
}else{
Ext.Msg.alert('Insert/Update','Keine Daten versendet!');
}*/
Ext.Msg.alert('Insert/Update','Daten sind angekommen');
//Ext.get('attributesGrid').getStore().reload();
//Ext.each(this.getStore().reload());
this.getStore().reload();
//this.grid.getStore().reload();
},
failure: function(){
Ext.Msg.alert('Insert/Update','Nichts angekommen');
}
});
},
scope:this
}];

Grid.superclass.initComponent.call(this);
}
});

Test.FinderAdmin.Grid = Grid;
})();
</script>
Can erverybody help me?

crashT
8 Mar 2011, 3:58 AM
Can everybody help me?

fay
8 Mar 2011, 4:06 AM
What error message are you getting?

Have you tried adding scope: this to the request's parameters?

Also, you could use the Ext.StoreMgr singleton to reload the store:



Ext.StoreMgr.lookup('attributesStore').reload();

crashT
8 Mar 2011, 4:40 AM
Hello Fay,

thank you for your help.

My error Message are "... is not a function"

Thanks again for your good tip

Ext.StoreMgr.lookup('attributesStore').reload();
Your tip works fine

fay
8 Mar 2011, 4:46 AM
Is that the full message? I'm guess that it's "...this.getStore() is not a function" ??

Did you add scope, or try Ext.StoreMgr?

emils
8 Mar 2011, 5:54 AM
you must use something like:


Ext.getCmp('Your Grid ID').getStore().load();


or reload() never mind...
becouse in that place of your code "this" is NOT your Grid!

crashT
8 Mar 2011, 6:25 AM
I use the Store Manager to make it work right away. Thanks for your help!
@emils ... "this" is probably at this point my Button
I have used this:

Ext.getCmp('attributesGrid').getStore().reload();Why does not it?

Both:
Ext.getCmp ('Your ID Grid') getstore () load ()..;
as well as:
Ext.getCmp ('Your ID Grid') getstore () reload ()..;

The store will be loaded not new!
Only with the Store Manager everything works.

emils
8 Mar 2011, 6:36 AM
well. .. Once you know that "this" is your button, be remembered that this.getStore () will return the error :)