PDA

View Full Version : Event order



mbko
15 Feb 2010, 11:56 PM
Hi all,
I am beginner in ExtJs. I have a problem with events in my search page.
There are GridPanel with PagingToolbar in bbar and TwinTriggerField in tbar, which I use for searching a record in grid. In onTrigger2Click function of TwinTriggerField I have a Ajax request to backend, which returns to me page number and record position in grid (grid is not filtered). With this params I do reload of JsonStore for a grid. Then I used a listener in this store:


listeners: {
'load': function(store, record, options) {
CustRegGrid.getSelectionModel().selectRow(options.params.record);
CustRegGrid.getView().focusRow(options.params.record);
}
}

where CustRegGrid is a grid variable and options.params.record is index of searched record. This code works fine, the record is selected and focused in grid. But if I step in FireBug, I see, that after calling this code is made a call to the onLoad function of GridView object, which returns view to first record of a page:


onLoad : function(){
this.scrollToTop.defer(Ext.isGecko ? 1 : 0, this);
},

this is on line 42202 of ext-all-debug.js

Is there any other event, which I can use and which is fired after onLoad function of GridView object to show specified record?

tobiu
16 Feb 2010, 1:53 AM
you can overwrite the method "loadRecords" in Ext.Data.Store and fire an event after load gets fired.

you can also use a delay for your calls in the onload-listener, like


myRowSelFn.defer(500);


it is not (yet?) possible to order listeners on one event in ext.

kind regards,
tobiu

mbko
16 Feb 2010, 3:24 AM
Thank you, delaying load listener helps.

Mike Robinson
16 Feb 2010, 8:00 AM
I have found that a very slight "delay" solves many problems. Not all browsers (especially >:) that >:) one >:) ...) are created equal. Events sometimes arrive slightly before the browser has finished doing what it needs to do. A delay of just a few milliseconds ... not nearly long enough to be noticeable ... can smooth-over a great many un-reproducible issues.

mbko
16 Feb 2010, 8:28 AM
I play with many delays and I set it to 150 millisecond, which works in any circumstance. The code for on load listener now looks like this (I include it for the beginners as I am):


listeners: {
'load': {delay: 150, fn:function(store, record, options) {
if (options.params.record) {
CustRegGrid.getSelectionModel().selectRow(options.params.record);
CustRegGrid.getView().focusRow(options.params.record);
};
}}
}

Thank you for all replies.