1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    56
    Vote Rating
    0
    dev_java is on a distinguished road

      0  

    Default How to get the selected row of a grid?

    How to get the selected row of a grid?


    Hi,

    In ext js 3.x , i was using the following code in RowSelectionModel to get the selected row in the grid.
    Code:
    var selHandler = new Ext.grid.RowSelectionModel({
    singleSelect : true,
    listeners: {	
    	rowselect: function(smObj, rowIndex, record) {
    		var row = Ext.getCmp('postionGrid').getView().getRow(rowIndex);		
    		var element = Ext.get(row);
    		element.removeClass('x-grid3-row-selected');
    		var cls = ''; 
    		var data=record.data;	    
    		switch (data.position) { 	       		
    			   case '4' : 		    	  
    				  cls = 'x-grid3-row-selected-4';
    				  break; 
    			   case '3' : 
    				  cls = 'x-grid3-row-selected-3' ;
    				  break; 
    			   case '2'  : 
    				  cls = 'x-grid3-row-selected-2' ;
    				  break; 
    			   default: 
    				  cls = 'x-grid3-row-selected' ;
    				  break; 
    			 
    		   }	      
    		element.addClass(cls);
    	}
    });
    On migrating to Ext js 4 , i have changed my code like this
    Code:
    var selHandler = Ext.create('Ext.selection.RowModel',{
    singleSelect : true,
    listeners: {	
    	select: function(smObj, record, index) {
    		var row = Ext.getCmp('postionGrid').getView().getRow(index);		
    		var element = Ext.get(row);
    		element.removeClass('x-grid3-row-selected');
    		var cls = ''; 
    		var data=record.data;	    
    		switch (data.position) { 	       		
    			   case '4' : 		    	  
    				  cls = 'x-grid3-row-selected-4';
    				  break; 
    			   case '3' : 
    				  cls = 'x-grid3-row-selected-3' ;
    				  break; 
    			   case '2'  : 
    				  cls = 'x-grid3-row-selected-2' ;
    				  break; 
    			   default: 
    				  cls = 'x-grid3-row-selected' ;
    				  break; 
    			 
    		   }	      
    		element.addClass(cls);
    	}
    });
    But Ext.getCmp('postionGrid').getView().getRow(index) is not working as View doesnot have getRow() method. So how an i get the Selected Row of the grid, so that i can change its cls.

    Thanks in advance

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,525
    Vote Rating
    871
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Look at getNode method.

    If you want to get the selected then you can use the getSelectedNodes
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jun 2010
    Posts
    56
    Vote Rating
    0
    dev_java is on a distinguished road

      0  

    Default


    Thanks . It worked

Similar Threads

  1. Grid with one row selected
    By sofway in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 3 Aug 2010, 12:04 AM
  2. Use selected rows in Grid 1 to create Grid 2 in new window
    By papadiddy in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 12 Nov 2009, 8:22 PM
  3. Go to selected row in a grid
    By anakin2hawk in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 15 Jun 2009, 8:21 AM
  4. more than one row was selected in grid
    By michaelc in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 18 Mar 2008, 12:28 PM
  5. Replies: 0
    Last Post: 6 Jan 2008, 7:29 PM

Thread Participants: 1