View Full Version : ListView selection problem in tabbed panel

18 Nov 2010, 5:39 AM

I have a view containing a combo box and a tab panel with several subviews. One of them (which is not the active tab at the beginning) should display a list's content depending on the outer combo selection and preselect the first list item. This should work both at the first display of that tab and when changing the combo value. The list's content is provided by a store which gets loaded with a given parameter at the beginning and when the combo changes.

The change of the list's content triggered by the store load works fine, but not the selection of the first element.
I played around with various combinations of render, load, selectionchange events, but I sometimes run in the strange situation that I have a selectionCount of 0 inside the list's selectionchange event listener.
I assume that the loading of the store and the selection done by the select(0) method are executed in parallel and at the time of the selection change there is no valid selection any more.

Any ideas for solving the problem or how to generally tackle that kind of problem in a better way?

Thanks and regards,

23 Nov 2010, 4:11 AM
Since I still didn't understand the behaviour, I'm asking again in a more condensed form, hopefully someone can clarify on the matter:

- ListView with selectionchange-listener, store with load-listener
- inside load: list.select(0)
- inside selectionchange:list.getSelectedRecords()[0].get('id')
- when refreshing store with store.reload(), it happens that in selectionchange I don't have a selection
- how can that happen?

Regards, Geziefer

23 Nov 2010, 4:38 AM
You can only call select(n) when the ListView is rendered.

Since your listview is in a tabpanel it could be that is isn't rendered yet (unless you used deferredRender:false).

23 Nov 2010, 4:53 AM
Well, the situation happens after reloading the store of the list, so the tab panel and the view are there. But, I guess, what you describe is still vaild, when I do a store.reload() in a button click listener and a select(0) in the store's load listener, since it still has to render the list again to reflect the changes and then cannot select an item of it yet?
So, what should I do if I want to select the first item in a list whenever the store gets refreshed or the view opens for the first time?


23 Nov 2010, 4:59 AM
The store load event handler should fire after the list content has been rendered (because that is done from the datachanged event).

So calling select(0) from both the listview render event (in case the listview renders after loading) and the store load event (in case the store (re)loads after the listview has rendered) should work.

23 Nov 2010, 5:11 AM
Ok, thanks for the advice.
Still, I faced this kind of problem not for the first time - shouldn't I be able to control what happens after what instead of doing the same thing twice and hope for the best?


23 Nov 2010, 5:17 AM
Since you programmed it, you should know which happens first, rendering or loading.

23 Nov 2010, 5:25 AM
That's exactly what I'm not sure of - if I call load on a store, I understand that this is executed in parallel to other things on the view, that's why I need a listener for the load to know when it's done. But if I have several things (e.g. load and render) I want to know of when they are finished, how can I know in which order this is done? Maybe, I lack some principal knowledge of the frameworks behaviour, but I have the feeling, that I have a bunch of listeners and additionally commands which work in the backround and I just don't know the control flow through the application...