Extending the store in a subclass
January 6th, 2009I have a class A which defines a datastore:
this.NachrichtenDataStore = new Ext.data.JsonStore({
url : './ajax/nachrichten.php',
baseParams : {
action : 'load_nachrichten'
},
root : 'Vinoweb.nachrichtencollection.nachrichten',
totalProperty : 'Vinoweb.total',
fields : [{
name : "auftragsnummer",
mapping : "auftrag_auftragsnummer"
}]
});
As you can see, I am querying "nachrichten.php" with 1 parameter.
Now I defined a subclass B.
This subclass should use ALMOST the same store. For example there are the same fields, the same root, the same totalProperty and so on.
But I need to define a listener and an additional parameter "nachrichtenTyp" like:
this.NachrichtenDataStore = new Ext.data.JsonStore({
url : './ajax/nachrichten.php',
baseParams : {
action : 'load_nachrichten'
},
listeners : {
beforeload : {
scope : this,
fn : function(store) {
this.NachrichtenDataStore.baseParams.nachrichtenTy p = this.nachrichtenTypComboBox.getValue();
}
}
}
});
So i need the definition from the superclass A and some changes in the subclass B.
What is the right syntax for it? I didn't find any example in the documentation.
PS: Sure, I could copy the whole store from class A to class B and modify the values. But that is ugly...
Thank you,
Bernhard
I want to overwride and extend the datastore in the subclass.
As a first step, I can live with "overwrite only". Extending the store in the subclass would be the next step, but let's focus on the first problem.
Here is the superclass:
grid_base = Ext
.extend(Ext.grid.EditorGridPanel, {
initComponent : function() {
this.NachrichtenDataStore = new Ext.data.JsonStore({
url : './ajax/nachrichten.php',
baseParams : {
action : 'load_nachrichten'
},
root : 'project.nachrichtencollection.nachrichten',
totalProperty : 'Vinoweb.total',
fields : [{
name : "field1"
}, {
name : "field2"
}]
});
Ext.apply(this, {
store : this.NachrichtenDataStore,
cm : new Ext.grid.ColumnModel([{
header : "Absender Kunde",
width : 150,
dataIndex : 'field1'
}
]),
sm : new Ext.grid.RowSelectionModel({
singleSelect : false
})
}); // eo apply
// call parent
grid_base.superclass.initComponent
.apply(this, arguments);
} // eo function initComponent
});
And here is the inherited class:
grid_extended = Ext.extend(grid_base, {
initComponent: function(){
this.nachrichtenTypComboBox = new Ext.form.ComboBox({
store: new Ext.data.SimpleStore({
fields: ['index', 'name'],
data: [['offene_nachrichten', 'Offene Nachrichten'], ['historie', 'Historie']]
}),
displayField: 'name',
valueField: 'index',
value: 'offene_nachrichten',
mode: 'local',
typeAhead: true,
triggerAction: 'all',
editable: false,
selectOnFocus: true,
width: 135,
listeners: {
select: {
scope: this,
fn: function(combo, record, index){
this.NachrichtenDataStore.reload();
}
}
}
});
this.NachrichtenDataStore = new Ext.data.JsonStore({
url: './ajax/nachrichten.php',
baseParams: {
action: 'load_nachrichten'
},
listeners: {
beforeload: {
scope: this,
fn: function(store){
this.NachrichtenDataStore.baseParams.nachrichtenTy p = this.nachrichtenTypComboBox.getValue();
}
}
},
root : 'project.nachrichtencollection.nachrichten',
totalProperty : 'Vinoweb.total',
fields : [{
name : "field1"
}, {
name : "field2"
}]
});
Ext.apply(this, {
store : this.NachrichtenDataStore,
tbar: [this.nachrichtenTypComboBox]
}); // eo apply
// call parent
grid_extended.superclass.initComponent.apply(this, arguments);
} // eo function initComponent
});
As you can see, the grid_extended class is more complex because it has an additional combobox which is displayed in a toolbar and the value of the combobox is used to query the store.
You can also see, that the store is called "this.NachrichtenStore".
If I overwrite the "this.NachrichtenStore" in the subclass, it does not work and always the simple store from the superclass is used. When I comment out the "this.NachrichtenStore" in the baseclass, then it works.
So "this.NachrichtenStore" is not overwritten (or there is something wrong with my initialization).
PS: As you can see, i have to repeat "root, fields, totalproper and url" fields in the subclass. This is not good, I would rather prefer to use these values from the base class. But as mentioned, I can live with that if it is complicated to change that.
Thank you so much,
Bernhard
MyStore = Ext.extend(Ext.data.JsonStore,
{
url: 'foo',
baseParams: {}
}
);
#If you have any other info about this subject , Please add it free.# |