Ext JS Combobox Rowediting не отображает последнее значение после нажатия кнопки Обновить - PullRequest
0 голосов
/ 08 апреля 2020

Я получил эту строку с комбобоксом для моего проекта. Значение, отображаемое в редактировании строки, поступает из БД, после чего пользователь может редактировать значение в редактировании строки. У меня проблема, когда я редактирую комбинированный список в нем. После нажатия кнопки «Обновить» в поле со списком отображается предыдущее значение. Другие поля в порядке. С бэкендом тоже все в порядке, если я отправлю форму сетки. Единственная проблема сейчас - это дисплей со списком. У кого-нибудь есть идеи по этому поводу? Большое спасибо за продвинутый:)

Снимок экрана:

Это мой 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,

                        }
                    ]
                },                   
            ],

А вот и мой контроллер JS:

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 Ответ

0 голосов
/ 04 мая 2020

Tq для вашего ответа. Я исправил эту проблему раньше. Я изменил свой код рендерера, как показано ниже, и он работает:

showPrescriptionItem: функция (значение, метаданные, запись, 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];
}          

}

...