从RowEditing组件获取RowEditing或Grid(在本例中为组合框)

时间:2012-06-01 16:00:39

标签: extjs extjs4

我正在为组合框构建一个“修复”,因为当您打开行编辑器时,它会显示值字段而不是文本框中的显示字段。但是,要做到这一点,我必须在发送到服务器之前更改组合框的值。为此,我的想法是挂钩行编辑插件的beforeedit事件。

最大的问题是,我无法找到一种方法来访问我正在进行行编辑的网格,或直接进行行编辑插件。

我唯一能找到的就是组合框与combobox.up('form')所在的形式,我可以勾选这些事件,但我认为它们不会“足够早”发生。我无法找到从表单中获取rowediting插件的方法:\

关于如何解决这个问题的任何想法?

修改1:

正如sha所要求的那样,问题显示为图像:

http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_1.png

http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_2.png

http://dl.dropbox.com/u/762638/Files/Images/Screenshots/show_combobox_extjs_problem/part_3.png

在这里你可以找到组合框代码:

Ext.define('Fdd.form.field.XComboBox', {
  extend: 'Ext.form.field.ComboBox',
  alias: 'widget.xcombobox',

  displayField: 'display',
  queryMode: 'local',
  valueField: 'value',
  //forceSelection: true,

  /**
   *
   * @property {Ext.form.Panel} parentForm
   * Contains a reference to the combobox form, used internally
   *
   * @readonly
   */
  parentForm: null,
  /**
   *
   * @property {Boolean} hasChanged
   * `true` if the combobox has changed its value since last show/hide cycle
   */
  hasChanged: false,

  statics: {
    xcomboboxRenderer: function(xcombobox) {
      return function(value, metaData, record, rowIndex) {
        if (value === null)
          return '';
        return xcombobox.store.getById(value.toString()).get('display');
      }
    }
  },

  initComponent: function() {
    var me                  = this;
    var xComboBoxStoreClass = 'Fdd.data.XComboBoxStore';
    var xComboBoxStoreKey   = Ext.getClassName(me);

    // FIXME: Fix default value to be display and not value field
    // Create the combo store if not exists
    me.createComboStoreIfNotExists = function() {
      // If store is not set, we can't do anything
      if (!me.store)
        return false;

      // If the store is an array, we break the functionality and return to a normal combobox
      // because XComboBox is to avoid problems with stores
      if (Ext.isArray(me.store))
        return false;

      // We need the object for the parent store, to avoid missing references
      var parentStore = null;
      if (Ext.isString(me.store))
        parentStore = Ext.getStore(me.store)
      else
        parentStore = me.store;

      // If the store doesn't have the updatedAt variable, we don't enable functionalities
      // because that is a requirement
      if (!Ext.isDefined(parentStore.updatedAt))
        return false;

      // If parent store is of type XComboBoxStore, it means that we already have created a combo store
      if (Ext.getClassName(parentStore) == xComboBoxStoreClass)
        return false;

      var comboStore = Fdd.NamespaceKeyedStoreManager.lookup(xComboBoxStoreKey, parentStore.storeId);
      if (!comboStore) {
        comboStore = Ext.create(xComboBoxStoreClass, parentStore);
        Fdd.NamespaceKeyedStoreManager.register(xComboBoxStoreKey, parentStore.storeId, comboStore);
      }
      me.store = comboStore;

      //me.on('afterrender', function(obj, eOpts) {
      //  obj.setValue(1);
      //});

      return comboStore;
    }

    // Load data if required
    me.loadUpdatedData = function() {
      me.createComboStoreIfNotExists();
      if (me.store)
        Fdd.NamespaceKeyedStoreManager.lookup(xComboBoxStoreKey, me.store.parentStore.storeId).loadIfNotUpdated();
    };

    // Load data if required
    me.loadUpdatedData();

    // Fires loadUpdatedData every time trigger is pressed
    me.on('expand', function(obj) {
      obj.loadUpdatedData();
    });

    // TODO: Building a fix for the problem combobox input field shows the value field instead of the display field
    me.on('boxready', function(obj) {
      obj.parentForm = obj.up('form');
      console.log(obj.parentForm);
      obj.mon(obj.parentForm, 'edit', function(editor) {
        console.log("beforeaction");
        console.log(e.originalValue);
        console.log(obj);
        if (!obj.hasChanged)
          obj.setValue(obj.originalValue);
      });
      obj.mon(obj.parentForm, 'show', function() {
        /*console.log("move:");
        console.log(obj.getValue());
        console.log(obj.inputEl.dom.value);*/
        obj.hasChanged = false;

        if (obj.parentForm) {
          if (obj.getValue() === null)
            obj.inputEl.dom.value = "";
          else
            obj.inputEl.dom.value = obj.store.getById(obj.getValue().toString()).get('display');
        }
      });
    });
    me.on('change', function(obj) {
      obj.hasChanged = true;
    });

    // Call parent initializator
    me.callParent(arguments);
  }
});

我们谈论的代码从TODO开始。

我建议忽略上一部分因为用于创建存储副本以避免过滤和缓冲存储。

编辑2:

似乎我试图通过这个问题解决的问题与我试图解决的问题没有直接关系(以不同的方式解决)所以问题可以被关闭。

非常感谢。

1 个答案:

答案 0 :(得分:1)

标准的Combobox控件中没有任何错误。我在我的项目的许多地方使用它没有任何问题。

确保在编辑器组合框,网格组合框和存储本身中具有valueFields的匹配类型。