Simple function that will return the selected record index of the extjs4 grid passed to it

Here’s a real time saver, adding this code at the top of the page will add a function named getSelectedRowIndex , and as the name suggests it returns the selected index, or -1 if there is no selection on the grid.

getSelectedRowIndex =  function(grid){
			var r = grid.getSelectionModel().getSelection();
			var s = grid.getStore();
			return s.indexOf(r[0]);
		}

Use it like this

var rowIndex = getSelectedRowIndex(grid);

2 thoughts on “Simple function that will return the selected record index of the extjs4 grid passed to it

  1. Pingback: Extending extjs’s selection model to get the rowIndex on a rowClick | Learn Some Things

Leave a Reply