Results 1 to 9 of 9

Thread: Selected records on list are incorrect

  1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    16
    Vote Rating
    0
      0  

    Question Selected records on list are incorrect

    Anyone know what I could be doing wrong? The selected item is incorrect when I log it to the console. It appears correct visually, but it returns the wrong record.

    Code:
    Ext.setup({
    	tabletStartupScreen: 'tablet_startup.png',
    	phoneStartupScreen: 'phone_startup.png',
    	icon: 'icon.png',
    	glossOnIcon: false,
    	onReady : function() {
    		Ext.regModel('Location', {
    			fields: ['name', 'state_name']
    		});
    		        
    		var locationListBase = {
    			listeners: {
    				itemtap: function(list, subIdx, el, e){
    					var selected  = list.getSelectedRecords();
    					console.info(selected) // Returns the wrong record, not the actually selected one
    				}
    			},
    			itemTpl: '<div class="contact2"><strong>{name}</strong></div>',
    			grouped: true,
    			store: new Ext.data.Store({
    				model: 'Location',
    				sorters: 'name',
    				getGroupString: function(record) {
    					return record.get('state_name');
    				},
    				proxy: {
    					type: 'ajax',
    					url : '/locations.json',
    					reader: {
    						type: 'json'
    					}
    				},
    				autoLoad: true
    			})
    		};
    		
    		var location_list = new Ext.List(locationListBase);
    		
    		var p = new Ext.Panel({
    			fullscreen: true,
    			dockedItems: [
    				{
    					dock : 'top',
    					xtype: 'toolbar',
    					title: 'App Title'
    				},
    			],
    			layout: 'card',
    			items: [location_list,{
    				html: 'Card 2'
    			}]
    	 	});
    		p.setActiveItem(0);
    		X = p
    	}
    });
    The JSON data returned looks like this:

    Code:
    [{"name":"Birmingham, MI","state_name":"Michigan"},{"name":"Cincinnati, OH","state_name":"Ohio"},{"name":"Farmington Hills/Farmington","state_name":"Michigan"},{"name":"Royal Oak, MI","state_name":"Michigan"},{"name":"Waterford, MI","state_name":"Michigan"},{"name":"West Bloomfield, MI","state_name":"Michigan"}]

  2. #2
    Ext User xnakxx's Avatar
    Join Date
    Sep 2010
    Location
    Central Valley Ca
    Posts
    84
    Vote Rating
    0
      0  

    Default

    the subIdx on the itemtap function be the index of the selected record within the list
    http://dev.sencha.com/deploy/touch/d...t.List-itemtap
    then using getStore() and getAt() you can select the record from the store

  3. #3
    Sencha User
    Join Date
    Dec 2010
    Posts
    16
    Vote Rating
    0
      0  

    Default Still not working

    This is still not working, same result as last with the wrong record being selected. Is it because of grouping?

    I changed the code as you suggested to:

    Code:
    Ext.setup({
    	tabletStartupScreen: 'tablet_startup.png',
    	phoneStartupScreen: 'phone_startup.png',
    	icon: 'icon.png',
    	glossOnIcon: false,
    	onReady : function() {
    		Ext.regModel('Location', {
    			fields: ['name', 'state_name']
    		});
    		        
    		var locationListBase = {
    			listeners: {
    				itemtap: function(list, subIdx, el, e){
                                            // Changed here:
    					var selected  = list.getStore().getAt(subIdx)
    					console.info(selected) // Returns the wrong record, not the actually selected one
    				}
    			},
    			itemTpl: '<div class="contact2"><strong>{name}</strong></div>',
    			grouped: true,
    			store: new Ext.data.Store({
    				model: 'Location',
    				sorters: 'name',
    				getGroupString: function(record) {
    					return record.get('state_name');
    				},
    				proxy: {
    					type: 'ajax',
    					url : '/locations.json',
    					reader: {
    						type: 'json'
    					}
    				},
    				autoLoad: true
    			})
    		};
    		
    		var location_list = new Ext.List(locationListBase);
    		
    		var p = new Ext.Panel({
    			fullscreen: true,
    			dockedItems: [
    				{
    					dock : 'top',
    					xtype: 'toolbar',
    					title: 'App Title'
    				},
    			],
    			layout: 'card',
    			items: [location_list,{
    				html: 'Card 2'
    			}]
    	 	});
    		p.setActiveItem(0);
    		X = p
    	}
    });

  4. #4
    Sencha User
    Join Date
    Dec 2010
    Posts
    16
    Vote Rating
    0
      0  

    Default

    It does seem to be the grouping. It works as expected when grouped is set to false on the list.

  5. #5
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    20
      0  

    Default

    Me too encountered similar issue.

    http://www.sencha.com/forum/showthre...d-on-Grouping.

  6. #6
    Sencha User
    Join Date
    Dec 2010
    Posts
    16
    Vote Rating
    0
      0  

    Default

    I'm still unable to get any kind of selection working with grouped lists. I'm assuming I must be doing something wrong or everyone's apps would be broken. This seems like a pretty major feature. Anyone see what's wrong with my code?

  7. #7
    Sencha User
    Join Date
    Dec 2010
    Posts
    16
    Vote Rating
    0
      0  

    Default

    It does work fine if I return the JSON in the exact order it will appear in when grouped and turn off the sorter option.

  8. #8
    Ext User
    Join Date
    Jul 2009
    Posts
    5
    Vote Rating
    0
      0  

    Default

    I was able to get around this issue with this:

    Code:
    listeners: {
                  itemTap: function (dv, index, item, e) {
                              var allItems = [];
                              var groupedItems = dv.getStore().getGroups();
                              for (var i=0; i<groupedItems.length; i++) {
                                          allItems = allItems.concat(groupedItems[i].children);
                              }
                              var clickedItem = allItems[index];
              }
    }

  9. #9
    Ext JS Premium Member SimonFlack's Avatar
    Join Date
    Jul 2010
    Location
    Norway
    Posts
    242
    Vote Rating
    3
      0  

    Default

    That worked for me too... Thanks ;-)
    Simon Flack
    CEO and UX Designer
    WhiteFox AS, Norway

    Web: www.whitefox.no

    Facebook: www.facebook.com/WhiteFoxAS

    Twitter: @WhiteFoxAS

Similar Threads

  1. Submitting selected records from a List to an Ajax request
    By GaryW in forum Sencha Touch 1.x: Discussion
    Replies: 4
    Last Post: 21 Jan 2011, 10:33 AM
  2. How to get selected records from itemSelector
    By rahulmca1@gmail.com in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 19 Oct 2009, 10:44 PM
  3. [SOLVED]PagingToolBar 1st page Records Displayed incorrect
    By maquejp in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 14 Oct 2009, 4:39 AM
  4. Keep selected records using pagination in Grid
    By mysticav in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 6 May 2009, 1:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •