Hybrid View
-
22 Aug 2012 12:58 AM #1
Scroll to view the selected list item function
Scroll to view the selected list item function
Hi,
We have an application that has a list with many items.
In Portrait mode on the iPad, the user can see about 5 items. We maintain a "currently" selected item in the list.
Is there a function that I can call, to ensure the currently Selected item is always visible?
For example...
Let's say there are 50 items in the list.
Then, let's say the user has scrolled down and selected item #40.
Then, the list gets refreshed.
After the list is reloaded, I need to call a function that will automatically scroll item #40 into view.
Is there such a function ?
Thanks
-
23 Aug 2012 12:09 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,634
- Vote Rating
- 435
You need to get the position of the selected item and then scroll to it.
*typed from top of my head*Code:var store = list.getStore(), selected = list.getSelection()[0], idx = store.indexOf(selected), els = list.container.getViewItems(), el = els[idx], offset = el.dom.offsetTop; list.getScrollable().getScroller().scrollTo(0, offset);Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 Sep 2012 3:03 AM #3
Uncaught TypeError: Cannot read property 'offsetTop' of undefined
Error is showing
-
25 Sep 2012 4:54 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,634
- Vote Rating
- 435
may have to do Ext.get(el).dom.offsetTop then
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
25 Sep 2012 4:58 AM #5
Not workingCode:onItemTap: function(list, index, target, record, e) { var store = list.getStore(), selected = list.getSelection()[0], idx = store.indexOf(selected), els = list.container.getViewItems(), el = els[idx], offset = Ext.get(el).dom.offsetTop; list.getScrollable().getScroller().scrollTo(0, offset); }
-
25 Sep 2012 5:00 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,634
- Vote Rating
- 435
Which part? Have you tried anything else?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote