Multiselect search whole string

大憨熊 提交于 2019-12-19 12:51:34

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/28974034/multiselect-search-whole-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!