1

私はExtJs3.3.1でライブグリッドを使用していますが、この質問はExtJsにとってグローバルであると信じています。ストアのリスナーは、イベントがどのグリッドから発生したかをどのように知るのですか?

ここに理由といくつかのコードがあります。

ストアにリスナーがあり、更新時にグリッドで選択された行を知り、イベントを一時停止したいと思います。これはすべて、グリッドで選択を行い、その範囲のフィールドを更新し、選択全体でそのフィールドを更新できるようにするためです。行を強調表示するだけで、チェックボックスなしで選択が行われます。このリスナーは多くのグリッドで使用されているため、gridlistenerがパラメーターとして取得するものから取得する方法が必要ですが、それは保存、記録、およびアクションのみです。

Ext.override(Ext.ux.grid.livegrid.Store, {
    listeners: {
      'update': function(store, record, action) {
        if (action=='commit'){ //each update has 2 actions, an edit and a commit
          var selected = grid.getSelectionModel().getSelections();  //need to know which grid
          if (selected.length>1){ //if more than one row selected
            grid.suspendEvents();
            store.writer.autoSave = false;
            for(var i=0; i < selected.length; i++){
              if (this.fieldChanged) {
                for (var name in this.fieldChanged) { 
                  //get the field changed and update the selection with the value
                  if (selected[i].get(name)!=this.fieldChanged[name]){
                    selected[i].set(name, this.fieldChanged[name]);
                  }
                } 
              }
            }
            grid.resumeEvents();
            store.fireEvent("datachanged", store);
            store.writer.autoSave = true;
          }
        }
        if (action=='edit'){
          this.fieldChanged = record.getChanges()
        }
      }
    }
  });
4

3 に答える 3

1

拡張機能の方が簡単ですが、オーバーライドでも実行できます。

MyGridPanel = Ext.extend(Ext.ux.grid.livegrid.EditorGridPanel, { 
    initComponent: function(){  
        MyGridPanel.superclass.initComponent.call(this);
        this.store.grid = this;
    }
});

編集---オーバーライドでそれを行う方法を示しています、それはきれいではありませんが、それは便利です。

var oldInit = Ext.ux.grid.livegrid.EditorGridPanel.prototype.initComponent;
Ext.override(Ext.ux.grid.livegrid.EditorGridPanel, {
    initComponent: function(){
        oldInit.call(this);
        this.store.grid = this;
    }
});
于 2012-05-04T23:59:45.793 に答える
1

ストアを使用しているグリッドがさらにある可能性があります。できれば、Ext Js 4では、次のようにGridpanelクラスを観察します。

//Associate all rendered grids to the store, so that we know which grids use a store.
Ext.util.Observable.observe(Ext.grid.Panel);
Ext.grid.Panel.on('render', function(grid){
    if (!grid.store.associatedGrids){
        grid.store.associatedGrids=[];
    }
    grid.store.associatedGrids.push(grid);
});
于 2012-05-09T18:58:32.337 に答える
0

自分で解決策を見つけました。ライブグリッドをオーバーライドして、そのストアに自分自身への参照を含めます。

Ext.override(Ext.ux.grid.livegrid.EditorGridPanel, {
    listeners: {
      'afterrender': function(self) {
        this.store.grid = this.id;
      }
    }
  });

次に、ストアリスナーでstore.gridを参照できます

于 2012-05-04T13:46:59.077 に答える