如何停止点击组合框清除其值? [英] How do I stop a clicked combo box from clearing its value?

查看:250
本文介绍了如何停止点击组合框清除其值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编辑组合框值。但是,当我点击一个网格单元格旧值消失时,会发生什么呢?我想保留一个,也避免用户从组合框本身中选择值,而不是其他值在下拉菜单中

I'm trying to edit a combobox value. But what happens is when I click a grid cell the old value disappears I want to keep a the and also avoid the user to select the values form the combo box itself and not values other than those in the drop down

如何实现这两件事。

{
    text: 'Food Items',
    xtype: 'gridcolumn',
    dataIndex: 'food_lister',
    flex: 1,
    renderer: function (value) {
        console.log()
        if (Ext.isNumber(value)) {
            var store = this.getEditor().getStore();
            return store.findRecord('foodid', value).get('fooddescp');
        }
        return value;
    },
    editor: {
        xtype: 'combobox',
        allowBlank: true,
        displayField: "fooddescp",
        valueField: "foodid",
        queryMode: 'local',
        mapperId: 'getfooddescrip',
        lastQuery: '',
        forceSelection: true,
        listeners: {
            expand: function () {
                var call = this.up('foodgrid[itemId=fooditemgrid]').getSelectionModel().selection.record.data.foodname.trim();
                this.store.clearFilter();
                //this.store.filter('call',call);
                this.store.filter({
                    property: 'call',
                    value: call,
                    exactMatch: true
                })
            }
        }
    }
}

推荐答案

在组合中使用可编辑:false 例如


点击这里

编辑:根据您的评论,如果您仍然想要使用可编辑的true并限制除了存储之外的其他值,您必须在单元格编辑事件中处理它。 validateedit / p>

As per your comment if you still want to use editable true and restric the value other than the store you have to handle it in cell editing event validateedit

 plugins: {
    ptype: 'cellediting',
    clicksToEdit: 1,
    listeners: {
        validateedit: function( editor, context, eOpts ){
            var store = context.column.getEditor().store,
                record = context.record;
           if(store.find('id',context.value) === -1){
             context.cancel = true;
           }
        }
    }
}

代码是基于我的例子。请检查我的小提琴中的运行示例

Above code is based on my example. Please check running example in my fiddle

这篇关于如何停止点击组合框清除其值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆