Search code examples
extjscomboboxmodelstore

Extjs combobox to display store records based on a property


I am new to Sencha and my question is the following:

by calling the store 'Media' in a combobox:

xtype: 'combobox', itemId: 'mediaPicker', store: Ext.create('web.store.Media'), fieldLabel: 'Image', emptyText: 'Choose an Image'

I receive a list of media as expected, but, how can I receive a list of only images, based on the following property in the store's model:

{ name: 'type', type: 'int' },

where type == 1 for images.

Thank you.


Solution

  • You need to add a filter to your store.

    Change store: Ext.create('web.store.Media') to something like

    store: Ext.create('web.store.Media',{
        filters: [{
            property: 'type',
            value: 1
            }])
    

    Note: I'm not sure whether the above will do a strict === or a loose == comparison. If it's not working for you then you can specify the filter on the store using a function. Check out the store filtering documentation.