1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    56
    Vote Rating
    0
    donalconlon is on a distinguished road

      0  

    Default datachanged event no workie for me.

    datachanged event no workie for me.


    Im trying to add a listener to my dataModel when it's reloaded with new data. But it doesn't seem to fire.

    Code:
    var dataModel;
            this.dataModel = new YAHOO.ext.grid.XMLDataModel(schema);
    		this.dataModel.onLoad.subscribe(this.onLoad.createDelegate(this));
            
    		this.dataModel.addListener('datachanged',this.dataChanged);
    I'm just trying to fire a simple alert

    Code:
    	dataChanged : function(){
    		alert('rows:' + this.dataModel.getRowCount())
    	},
    I"m trying to call the method after I reload the data using :

    Code:
    search : function(e){
            getEl('load-ind').show();
            var params = {"list" : "New%20RFC's","keyField":"SVP%5Fx0020%5FApprover","query": e};
    
    		this.dataModel.load(...,,this.clearIndicator);
    And another thing. If I put an alert() in 'clearIndicator', it does not fire. Why is this?

    Code:
     clearIndicator : function(file){
            getEl('load-ind').hide();
    alert('dataLoaded');
        },

  2. #2
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    You are looking for the 'load' event, not datachanged. I don't think datachanged is ever fired internally, it's there for subclasses to have a way to notify observers (like the grid) that the entire data has changed and needs to be rerendered (for example if you overwrite the "data" internal variable).

    An XHR load fires a sequence of events - rowsdeleted, rowsinserted and then load.

  3. #3
    Ext User
    Join Date
    Mar 2007
    Posts
    56
    Vote Rating
    0
    donalconlon is on a distinguished road

      0  

    Default


    Thanks Jack.

    I did actuall try 'load', but I was using:

    this.dataModel.addListener('load',this.onLoad);

    but if I use:

    this.dataModel.addListener('load',this.onLoad.createDelegate(this));

    it works. No sure why the first doesn't.

  4. #4
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    The best way is:

    this.dataModel.on('load',this.onLoad, this, true);

    This way you only bind the scope once (I also like the shorter "on").

  5. #5
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,505
    Vote Rating
    53
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Quote Originally Posted by donalconlon
    Thanks Jack.

    I did actuall try 'load', but I was using:

    this.dataModel.addListener('load',this.onLoad);

    but if I use:

    this.dataModel.addListener('load',this.onLoad.createDelegate(this));

    it works. No sure why the first doesn't.
    I've been tring to explain this to my colleague who I have trying to create a Date/time input widget+JSP tag.

    Think of the function parameter as being a C function pointer. All the addListener function receives is a function pointer. It has no concept of what the "this" should be at the time in the future that that function will be called. By default, in browsers it is the "window" object.

    That's why the next parameter to addListener is "scope", and the next again is override. That means override the default scope with the passed scope.

    createDelegate is another way to bind a scope to a function.

Similar Threads

  1. how to stop click event when having dblclick event
    By seldon in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 8 Nov 2011, 12:31 AM

Thread Participants: 2