Search code examples
extjsextjs4extjs6extjs6-classic

Extjs 6 Define a chained store using Ext.define


Can a chained store be define using Ext.define statement? I tried the following code but I'm getting errors:

Ext.define('MyProject.store.RelFiltered', {
    extend: 'Ext.data.ChainedStore',
    source:'MyProject.store.Rel',
    alias: 'store.releasesFiltered'
});

The errors I receive are:

Ext.data.ChainedStore.applySource(): Invalid source "MyProject.store.Rel" specified for Ext.data.ChainedStore

and

Ext.mixin.Bindable.applyBind(): Cannot use bind config without a viewModel

I got the idee from this post, but it seems that the code is incomplete.

Thank you


Solution

  • Can a chained store be define using Ext.define statement?

    Definitely yes. But the source config of the chained store says that it should be either a store instance or the id of an existing store.

    So the code would look like this:

    Ext.define('MyApp.store.MyChainedStore', {
        extend: 'Ext.data.ChainedStore',
    
        storeId: 'MyChainedStore',
        //source using storeID
        source: 'OriginalStore'
    
    });
    
    Ext.define('MyApp.store.OriginalStore', {
        extend: 'Ext.data.Store',
    
        requires: [
            'Ext.data.field.Field'
        ],
    
        storeId: 'OriginalStore',
        data: [{
            id: 1,
            name: 'commodi'
        }],
        fields: [{
            name: 'id'
        }, {
            name: 'name'
        }]
    });
    

    Check out this fiddle example https://fiddle.sencha.com/#view/editor&fiddle/1kk4