0
votes

i use a livegrid in ExtJs 3.3.1 but believe this question is global to ExtJs. How does a listener on a store know which grid the event comes from ?

Here why and some code.

I have a listener on a store and on update i would like to know which rows were selected in the grid and also suspend the events. This all so that i can make a selection in the grid, update a field in that range and update that field in the whole selection. Selection is done without a checkbox, just by highlighting the rows. Since this listener is used by many grids i need a way to get it froml what the gridlistener gets as parameters but that is only store, record and action

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()
        }
      }
    }
  });
3
What exactly are you trying to accomplish? Grid should update its stuff automatically. It's not clear from your question what real problem issha
the problem is, i use this listener for many grids and i need to know in the listener itself which grid it is handling at that momentpeter
I understood that. What exactly are you trying to do in the listener? Looks like you're manually updating the grid and that should happen automaticallysha
Ah...no, the user wants to fill in multiple rows with the same fieldvalue, so he selects the rows, edits just one field and the rest of the selected rows is also replaced with this value in this field, this works now cause i know which grid i'm working on but this should work for all gridspeter
Interesting idea. But yes, then you need to know what is selected in the grid. But this should be grid handler, no? Why are you trying to do this on the store level?sha

3 Answers

1
votes

It would be easier in an extension but it can be done in an override as well.

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

edit --- Showing how to do it in an override, it isn't pretty but it is useful.

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;
    }
});
1
votes

There may be more grids using the store. Preferably in Ext Js 4 you observe the Gridpanel class like so:

//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);
});
0
votes

Found a solution myself, i override the livegrid to include a reference to itself in its store like so

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

Then in my store listener i can refer to store.grid