View Full Version : RowSelectionModel events

16 Aug 2010, 6:30 AM

I'm trying to have a grid with a rowselectionmodel start with all the rows selected. I added a line like this in my viewport init (based on other forum posts I've found here):

this.servicesList.store.on('load', selectAllList, this.servicesList);

sevicesList is my grid, selectAllList just does this.servicesList.selModel.selectAll().

What is odd is that sometimes the grid will be selected (which is what I want), but sometimes it is not. Also I have several of these grids on my page and it seems random which will actually selectAll. I sometimes see it blink from all selected to none selected so I think there must be another event that is de-selecting everything.

Anyone have some insight into where I might put this event to get these rows all selected at start? I'm kind of lost with the designer as to the order of things or where I might put arbitrary code that would run once everything is rendered/loaded.


16 Aug 2010, 7:36 AM
Hi cichlid80,

Try this line instead:

this.servicesList.store.on('loadl', function(){
}, this);

// or...
this.servicesList.store.on('load', selectAllList, this);

The second parameter to on is the function (which you have), and the third parameter is the scope, which will determine what "this" represents in the callback function. Since you are passing in the grid, "this" will refer to the grid...however, you are calling this.servicesList.selModel.selectAll(). You could also do this and keep that line of code the same:

var selectAllList = function(){

If you pass in the grid for the scope, than you can just call "this.selModel" since "this" represents the grid.

Let me know if that makes sense and if you get it working. Thanks!

16 Aug 2010, 12:02 PM
Thanks for the detailed response! It does work but it is still intermittent. I'm not sure why but if I hit refresh it seems like every-other time it will either work or not - but each time it doesn't work, I see it select all the rows correctly before updating itself to not select any (all in the fraction of a second the page takes to load). This is in Chrome. In IE 7, it works maybe once every 10 times. I still think I'm getting foiled by the selection model doing a deselect all after it loads or something similar but haven't looked at it's constructor.

Is there any way to make a function that won't run until the entire page is rendered? It seems not as elegant but safer in terms of getting these particular settings to stick. Thanks again!

16 Aug 2010, 12:21 PM
Hmm. Maybe you can try the "viewready" event of the GridPanel. That might provide the proper timing for you. Let me know if that works. You can alternatively also try the "refresh" event of the GridView.