0

I have a multiselect with search bound to a store (with attribute string_value). Search only searches strings that start with "string to search" instead of contains "string to search" (similar to searching for '%string%' instead of 'string%'). Is there a way to do this by extending 'multiselector-search'?

Below is my multiselector control bound to a form:

var ms = Ext.widget('form', {
    xtype: 'multi-selector',
    width: 400,
    height: 300,
    requires: [
    'Ext.view.MultiSelector'
    ],
    layout: 'fit',

    renderTo: Ext.getBody(),
    items: [{
        bbar: [{
            xtype: 'button',
            itemId: 'button',
            html: 'Toolbar here',

            text: 'Submit request to API',

            // get submitted array
            handler: function() {
                if (cardioCatalogQT.config.mode === 'test') {
                    console.log('In submitted values handler: ');
                }

                var submitted = Ext.getCmp('test');

                var dx = [];
                Ext.Array.each(submitted.store.data.items, function (item) {
                    dx.push(item.data.string_value);
                }); // each()

                Ext.Msg.alert('Submitted Values',
                   'The following diagnoses will be sent to the server:  <br      
                />' + dx);

                if (cardioCatalogQT.config.mode === 'test') {
                    console.log(dx);
                }
            }
        }],
        xtype: 'multiselector',
        title: 'Selected Dx',

        id: 'test',
        name:'test',
        fieldName: 'string_value',

        viewConfig: {
            deferEmptyText: false,
            emptyText: 'No Dx selected'
        },
        // TODO: fix ability to remove selected items when box is unchecked
        search: {
            field: 'string_value',
           store: 'Diagnoses'

        }
    }]
}).center();

The closest I could find to this problem was http://www.sencha.com/forum/showthread.php?240887. I tried making it work with the multiselect search with no success.

horcle_buzz
  • 2,101
  • 3
  • 30
  • 59
  • Perhaps you can add an example of what you are doing on fiddle.sencha.com and we can easier try to help you. – Rob Schmuecker Mar 11 '15 at 07:41
  • Done: https://fiddle.sencha.com/#fiddle/jav Use case would be that I want to search for all instances of a number in my string, say '0.' Instead of typing the full value ('string_0'), simply typing '0' should get me all desired instances from the list (suppose there was also 'string_10' in the list). – horcle_buzz Mar 11 '15 at 16:06

1 Answers1

3

The MultiSelector uses the Ext.util.Filter to narrow the results based on the typed text. You need to enable the anyMatch property for it to match anywhere.

To do that, you'll have to include a new "search" function in your multiselector's search object that will have anyMatch=true.

Please see my fiddle, https://fiddle.sencha.com/#fiddle/jf5, for an example of how to do this.

Greg McGrath
  • 527
  • 3
  • 13