Dave.Sanders
17 Sep 2009, 7:53 AM
Hey all, I had some simple array data that I needed for a dropdown that I couldn't turn into a multi-dimensional array since the data was being generated elsewhere. Seeing another question on the forums about how to plug single-dimension arrays into a store, I decided to create a dirt-simple ux to handle this.
Ext.ux.SingleArrayReader = Ext.extend(Ext.data.ArrayReader, {
readRecords : function(o){
var a = [];
for (var i=0; i<o.length; i++) {
a[a.length] = [i, o[i]];
}
return Ext.ux.SingleArrayReader.superclass.readRecords.call(this, a);
}
});
Ext.ux.SingleArrayStore = Ext.extend(Ext.data.ArrayStore, {
constructor: function(config){
if (!config) {config = {};}
if (!config.fields) {
config.fields = ['id', 'text'];
}
//bypass the arraystore constructor on purpose
Ext.data.ArrayStore.superclass.constructor.call(this, Ext.apply(config, {
reader: new Ext.ux.SingleArrayReader(config)
}));
},
loadData : function(data, append){
Ext.data.ArrayStore.superclass.loadData.call(this, data, append);
}
});
Usage is very simple:
var myStore = new Ext.ux.SingleArrayStore();
If you don't pass any config, then it will create the fields "id" and "text" for you. Then you reference those in a combo the same way you reference any other store.
Let me know if you have any bugs or questions.
Dave
Ext.ux.SingleArrayReader = Ext.extend(Ext.data.ArrayReader, {
readRecords : function(o){
var a = [];
for (var i=0; i<o.length; i++) {
a[a.length] = [i, o[i]];
}
return Ext.ux.SingleArrayReader.superclass.readRecords.call(this, a);
}
});
Ext.ux.SingleArrayStore = Ext.extend(Ext.data.ArrayStore, {
constructor: function(config){
if (!config) {config = {};}
if (!config.fields) {
config.fields = ['id', 'text'];
}
//bypass the arraystore constructor on purpose
Ext.data.ArrayStore.superclass.constructor.call(this, Ext.apply(config, {
reader: new Ext.ux.SingleArrayReader(config)
}));
},
loadData : function(data, append){
Ext.data.ArrayStore.superclass.loadData.call(this, data, append);
}
});
Usage is very simple:
var myStore = new Ext.ux.SingleArrayStore();
If you don't pass any config, then it will create the fields "id" and "text" for you. Then you reference those in a combo the same way you reference any other store.
Let me know if you have any bugs or questions.
Dave