在Grid中的Combobox中获取密钥

时间:2013-05-27 22:36:23

标签: extjs4

当用户使用行编辑保存行时,我无法在网格中获取组合框的值。我在组合框上有一个on select事件,它将键保存到变量中。这是正确的方法吗?

这是我到目前为止所拥有的

        function renderAccountSynch() {

            var allCustomer = {!allCustomers};
            var accountSyncData = {!accountSyncRecordsJSON};

            //model for account sync
            Ext.define('accountSyncModel', {
                extend: 'Ext.data.Model',
                idProperty: 'accountId',
                fields: [
                    {name: 'accountId', type: 'string'},
                    {name: 'accountName', type: 'string'},
                    {name: 'customerName', type: 'string'},
                    {name: 'customerId', type: 'string'},
                    {name: 'isSynched', type: 'boolean'}
                ]
            });

            var store = Ext.create('Ext.data.Store', {
                model: 'accountSyncModel',
                data: accountSyncData
            });


            var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
                clicksToMoveEditor: 1,
                autoCancel: false,
                saveBtnText : "Sync",
                cancelBtnText : "Cancel"
            }); 

            // create reusable renderer
            Ext.util.Format.comboRenderer = function(combo){
                return function(value){
                    var record = combo.findRecord(combo.valueField, value);
                    return record ? record.get(combo.displayField) : combo.valueNotFoundText;
                }
            }

            // create the combo instance
            var combo = new Ext.form.field.ComboBox({
                id: 'comboId',
                typeAhead: true,
                triggerAction: 'all',
                selectOnTab: true,
                //store:[{!allCustomersOptions}],
                store: new Ext.data.Store({

                    fields: [
                        {name: 'key',
                        name: 'label'}
                    ],
                    data: {!allCustomersOptions}
                }),
                valueField: 'key',
                displayField: 'label',
                lazyRender: true,
                listClass: 'x-combo-list-small'
            });

            var grid = Ext.create('Ext.grid.Panel', {

                height: 450,
                forcefit: true,
                frame: true,
                title: 'Customer Sync',
                renderTo: 'syncCustomersId',
                store: store,
                plugins: [rowEditing],

                columns: [{
                    header: 'Account Name',
                    width: 100,
                    flex: 1,
                    sortable: true,
                    dataIndex: 'accountName'
                },

               {
                header: 'Customer Name',
                dataIndex: 'customerName',
                width: 100,
                flex: 1,
                editor: combo
                },

                {               
                    xtype: 'checkcolumn',
                    header: 'Synched',

                    processEvent: function () { return false; },
                    dataIndex: 'isSynched',
                    width: 55
                }

               ],

            }
            );//end grid creation

            //this event fires when a row in the grid has been updated and saved
            grid.on('edit', function(editor, e) {

                   //call save data function which saves the record to SF
                   syncData(e.record);

            }); 

            combo.on('select',function(combo, records) {
                Ext.Msg.alert(records[0].get('key'));
                selectedComboValue = records[0].get('key')
            });

        }


        var selectedComboValue;

        function syncData( record, combo){

            var accountId = record.get('accountId');
            var customerId = selectedComboValue; // record.get('label');

            console.log('--> aocountId = ' + accountId + '   customerId = ' + selectedComboValue );

            RenderAdminController.syncAccount(
                accountId, customerId,
                //callback function
                function(result, event) {
                    if(event.status) {
                        record.set('isSynched', true);

                        record.commit();
                    } else {
                        //Error
                        Ext.Msg.alert('Error ' + event.message);
                    }

                },
                { 
                    escape : true 
                }
            ); 

        }

1 个答案:

答案 0 :(得分:1)

尝试修复combo商店的字段:

            store: new Ext.data.Store({

                fields: [
                    {name: 'key'},
                    {name: 'label'}
                ],
                data: {!allCustomersOptions} // <= BTW what's this???
            }),