ExtJS Combobox Rowediting在单击更新后不显示最新值

Posted

技术标签:

【中文标题】ExtJS Combobox Rowediting在单击更新后不显示最新值【英文标题】:ExtJS Combobox Rowediting Not Displaying The Latest Value After Click Update 【发布时间】:2020-04-08 02:35:59 【问题描述】:

我为我的项目使用组合框进行了这一行编辑。 rowediting 中显示的值来自 DB,然后用户可以在 rowediting 中编辑该值。我在其中编辑组合框时遇到问题。单击更新后,组合框会显示回以前的值。其他领域没问题。如果我提交网格表单,后端也可以。现在唯一的问题是组合框显示。有人对此有任何想法吗?非常感谢您:)

屏幕截图:

这是我的 JS 代码:

        items: [
                       
                    xtype: 'grid', 
                    name: 'prescriptionGrid', 
                    reference: 'prescriptionGrid', flex: 1, height: 200, scrollable: true,
                    store:  
                        type: 'array' , 
                        fields: ['id', 
                        'inventorycatid', 
                        'stationid',  
                        'route', 
                        'frequency', 
                        'dose',  
                        'duration',
                        'medicationName',
                        'quantity'] 
                    ,
                    listeners: 
                        validateedit: 'prescriptionGridItemValidate',
                        beforeedit: 'prescriptionbeforeedit',

                    , 
                    columns: [ 
                          text: 'Max Request Quantity', hidden: true, dataIndex:'maxRequestQuantity' ,
                        //  text: 'Created By', hidden: true, dataIndex:'createdby', name: 'createdby', value: data.createdbyname, reference:'createdby',,
                          text: 'Medication Name', 
                           dataIndex: 'inventorycatid', 
                           flex: 4, 
                           reference: 'medicationName',
                           renderer: 'showPrescriptionItem', 
                           editor:  
                               xtype: 'combobox', 
                               name: 'inventorycatid', 
                               minChars: 0, 
                               queryMode: 'remote', 
                               queryParam: 'cbxname',

                               store: 
                                    type: 'InventoryCat',
                                    autoLoad: true,
                                    remoteFilter: true,
                                    filters: [ property: 'typename', value: 'Inventory:Medicine' ],
                                ,
                                /* remoteFilter: false, */
                                valueField: 'id',
                                displayField: 'name',
                                forceSelection: true,
                                editable: false,
                                allowBlank: false,
                                listeners: 
                                    select: 'inventorycatComboSelected',

                                
                            
                        ,
                          text: 'Route', 
                           dataIndex: 'route', 
                           flex: 2, 
                           reference: 'route',
                           editor: 
                               xtype: 'combobox',
                               queryMode: 'local',
                               displayField: 'name',
                               valueField: 'name',
                               store: [
                                     id: '250', name: 'Tab (Tablet)' ,
                                     id: '251', name: 'Caps (Capsule)' ,
                                     id: '252', name: 'Syrup' ,
                                     id: '253', name: 'IM (Intramuscular)' ,
                                     id: '254', name: 'IV (Intravenous)' ,
                                     id: '255', name: 'LA (Local Application)' ,
                                     id: '256', name: 'SL (Sublingual)' ,
                                     id: '257', name: 'SC (Subcutaneous)' ,
                                ],
                            editable: false,
                            name: 'route'
                        
                        , 
                          text: 'Dose',
                           dataIndex: 'dose',  
                           flex: 1,  
                           reference: 'dose',
                           editor: 
                               name: 'dose', allowBlank: false
                            
                        ,
                          text: 'Frequency',
                           dataIndex: 'frequency',
                           flex: 2, 
                           reference: 'frequency',
                           editor: 
                            xtype: 'combobox',
                            queryMode: 'local',
                            displayField: 'name',
                            valueField: 'name',
                            store: [
                                 id: '250', name: 'Daily' ,
                                 id: '251', name: 'Every other day ' ,
                                 id: '252', name: 'BD (2x a day)' ,
                                 id: '253', name: 'TDS (3x a day)  ' ,
                                 id: '254', name: 'QID (4x a day)' ,
                                 id: '255', name: 'Q4h (Every 4 hrs)' ,
                                 id: '256', name: 'Q4h-6h (Every 4 to 6 hrs)   ' ,
                                 id: '257', name: 'qwk (every week)' ,
                            ],
                            name: 'frequency', allowBlank: true
                            
                        ,
                          text: 'Duration', 
                           dataIndex: 'duration', 
                           flex: 1, 
                           reference: 'duration',
                           editor: 
                               name: 'duration', allowBlank: false
                            
                        ,

                         
                            text: 'Quantity',
                            dataIndex: 'quantity',
                            flex: 1,
                            reference: 'quantity',
                            editor: 
                                name: 'quantity', allowBlank: false 
                            
                        
                    ],                                        
                    selType: 'rowmodel',
                    plugins: [
                         ptype: 'rowediting', id: 'rowEditPlugin', clicksToMoveEditor: 1, autoCancel: false,

                        
                    ]
                ,                   
            ],

这是我的 ControllerJS:

showPrescriptionItem: function(value, metaData, record, rowIndex, colIndex, store, view) 
    console.log(record.data, "ShowPrescription"); //After edit, capture correct inventorycat but wrong medicationName
   // console.log(value, "ShowPrescription2");
    return record.get('medicationName') || this.getViewModel().get('inventoryMap')[value];

,

inventorycatComboSelected: function(combo, record) 
    var vm = this.getViewModel(),
        map = vm.get('inventoryMap');
    map[record.id] = record.data.name;
    vm.set('inventoryMap', map);

    console.log(record.data, "InventorycatSelected"); //After edit, capture correct id & name
    //return(map); 

    // var itemRecord = combo.up('editor').context.record;
,  

prescriptionGridItemValidate: function(editor, e) 
    rowIndex = e.rowIdx;

    var itemid = editor.editor.form.findField('inventorycatid').getValue();
    var unit = editor.editor.form.findField('quantity').getValue();

    if(!Ext.isNumeric(unit)) 
        Ext.Msg.alert('Error', 'Quantity must be in numeric');
        e.cancel = true;
    
    else if(parseInt(unit) < 0) 
        Ext.Msg.alert('Error', 'The quantity has to be 0 or more');
        e.cancel = true;
    
    else 
        e.cancel = false;
    
    console.log(e.newValues,'context')
,

prescriptionbeforeedit: function(elemnt,cell)
    if (cell.record.data.inventorycatid != '')
        elemnt.editor.form.getFields().items[0].setDisabled(true)
        elemnt.editor.form.getFields().items[0].setRawValue(cell.row.cells[0].textContent)
     else 
        elemnt.editor.form.getFields().items[0].setDisabled(false)
    
,

【问题讨论】:

哦抱歉顺便说一句,我的问题只是药物名称组合框,路线组合框没有问题。 您需要更新附加到网格的存储中的记录。 【参考方案1】:

Tq 你的回应。我之前已经解决了这个问题。我更改了我的渲染器代码如下,它可以工作:

showPrescriptionItem: function(value, metaData, record, rowIndex, colIndex, store, view)

var map = this.getView().getViewModel().get('inventoryMap');
var medicationName = record.get('medicationName');
//console.log(map[value], 'map value'); 

if(medicationName !== ''  && map[value] == undefined)  
    console.log(medicationName, "ShowPrescriptionOldVal");
    return  medicationName;         


else     
    console.log(map[value], "ShowPrescriptionNewVal");
    return map[value];
          

【讨论】:

以上是关于ExtJS Combobox Rowediting在单击更新后不显示最新值的主要内容,如果未能解决你的问题,请参考以下文章

ExtJS 4 使用 Ext.grid.plugin.RowEditing 基于另一个更改单元格值

Extjs rowEditing rownumberer,rownumbers总是0

使用 Ext.grid.Panel.reconfigure() 打破了网格 RowEditing 插件

Extjs3 combobox使用

Extjs 让combobox写起来更简单

ComboBox 在 ExtJS 的 EditorGridPanel 中不起作用