Reputation: 169
I am currently trying to keep a sorted store of Measures (in the musical sense) in app. I am struggling to get the sort functionality of the store to work. I have a model defined with the category of 'index'. My store is also defined as follows:
Ext.define('MusicNotationSoftware.store.Measures', {
extend: 'Ext.data.Store',
requires: [
'Ext.ux.parse.data.proxy.Parse',
'MusicNotationSoftware.model.Measure'
],
config: {
model: 'MusicNotationSoftware.model.Measure',
storeId: 'measuresStore',
autoLoad: true,
autoSync: true,
proxy: {
type: 'parse',
url: 'https://api.parse.com/1/classes/Measure'
},
sorters: [
{
property: 'index',
direction: 'ASC'
}
],
Since measures belong to Voices, I end up calling
voice.measures()
to get all measures associated with a single voice. To my knowledge this returns a store with all of the measures.
My question then is what is the best way to keep this list of measures sorted as I add measures to the store? Clearly the store that is returned is not the store defined as above.
Upvotes: 2
Views: 1023
Reputation: 4002
When you define the measures hasMany association in Voice, you should be able to set up the sorting there:
hasMany:[
{
model:'MusicNotationSoftware.model.Measure',
name:'measures',
storeConfig: {
sorters: [
{ property: 'index', direction: 'ASC' }
]
}
}
]
or similar.
Upvotes: 2
Reputation: 106
According to TomW's answer. It should be storeConfig instead of store.
hasMany:[
{
model:'MusicNotationSoftware.model.Measure',
name:'measures',
storeConfig :{
sorters: [
{ property: 'index', direction: 'ASC' }
]
}
}
]
It worked for me.
Upvotes: 0
Reputation: 147
You dont have to define a store for measures. Since the voice store has already populated measures as measures belong to voice.
All you have to do is call
voice.measures().sort('index', 'ASC')
This would sort all the measure record and sort them ascending-ly on the index field.
Upvotes: 0