ExtJS MultiSelect Edit - Not working for multi value selection

Viewed 158

I have a GridEditPanel where the 1st column is a combobox with multiSelect. The values are being loaded correctly from the DB and is being written in the DB correctly as well. In the event where the the combobox has a single value, the drop-down highlights the value correctly as well.

The issue is when the combobox has multiple values, it displays the values correctly, however during edit the multiple values are not selected.

Model:

extend: 'Ext.data.Model',
idProperty: 'contactTypeID',
fields: [
    {
        name: 'contactTypeID',
        type: 'string'
    },
    {
        name: 'contactType',
        type: 'string'
    }
],

View GridEditPanel

emptyText: "There are no contacts.",
insertErrorText: 'Please finish editing the current contact before inserting a new record',
addButtonText: 'Add Contact',

itemId: 'contacts',
viewConfig: {
    deferEmptyText: false
},
minHeight: 130,

initComponent: function () {
    var me = this,
        contactTypes;

    // Creating store to be referenced by column renderer
    contactTypes = Ext.create('Ext.data.Store', {
        model: '********',
        autoLoad: true,
        listeners: {
            load: function () {
                me.getView().refresh();
            }
        }
    });

    this.columns = [
        {
            text: 'Contact Role',
            dataIndex: 'contactRoleID',
            flex: 1,
            renderer: function (value) {
                // Lookup contact type to get display value
                //If a contact has multiple roles, use split by ',' to find display values.
                if (value.includes(',')) {
                    var a = value.split(','), i, contTypeIds = [];
                    var contTypes = new Array();

                    for (i = 0; i < a.length; i++) {
                        contTypeIds.push(a[i]);
                        contTypes.push(contactTypes.findRecord('contactTypeID', a[i], 0, false, false, true).get('contactType'));
                    }
                    console.log('Multi Render Return Value: ' + contTypes);
                    return contTypes;
                }
                else {//if not a contact will only have one role.
                    var rec = contactTypes.findRecord('contactTypeID', value, 0, false, false, true); // exact match
                    console.log('Single Render Return Value: ' + rec.get('contactType'));
                    return rec ? rec.get('contactType') : '<span class="colselecttext">Required</span>';
                }
            },
            align: 'center',
            autoSizeColumn: true,
            editor: {
                xtype: 'combobox',
                store: contactTypes,
                multiSelect: true,
                delimiter: ',',
                forceSelection: true,
                queryMode: 'local',
                displayField: 'contactType',
                valueField: 'contactTypeID',
                allowBlank: false
            }
        },
1 Answers

I cannot see the model of GridEditPanel, but I assume you are using the wrong field type, string instead of array (Have a look at the converter function, maybe it will help you to fix the problem). I wrote a small post in my blog about multiSelect combobox editor in editable grid. The sample works with v4.2 Hope it will help you to fix the bug.

Related