Login Register

getting a field value from a selected row via grid.selection.getSelected

The following all return "undefined":

var currentlySelected = grid.selection.getSelected()[0]['assignmentId'];
var currentlySelected = grid.selection.getSelected()[0].assignmentId;
var currentlySelected = grid.selection.getSelected()['assignmentId'];

Are any of these even close?

Can I even do this?

Thanks

getSelected() returns an array of row indexes

... you'll have pass the index to grid.model.getRow or grid.model.getDatum. The best way would probably depend on what type of model you are using, but something like this should work, if assignmentId is a field name in your model:

var currentlySelected = grid.model.getDatum(grid.selection.getSelected()[0], 'assignmentId');

Thanks wombat!

I actually did it differently, but what I did works fine. Here is the code:

function moveSelectedLeft(){
	var arrCurrentlySelected = rightGrid.selection.getSelected();
	var strSelectedList = "";

	for(var a = 0; a < arrCurrentlySelected.length; a++){
		var row= arrCurrentlySelected[a];
		var selected = rightGrid.model.data[row];
		
		strSelectedList = strSelectedList + " or assignmentId:" + selected['assignmentId'];
		console.debug('Move ' + selected['fullName'] + " with assignmentId: " + selected['assignmentId'] + ' to Hire List');
	}           

	if(strSelectedList){
		strSelectedList = strSelectedList.substr(3);
		//console.debug('String of assignmentIds is: ' + strSelectedList);
		updateStore(strSelectedList, 'Y'); 
		//console.debug('strSelectedList had a value and updateStore was run successfully.');		
	}else{
		console.debug('BUTTON CLICK with NOTHING SELECTED');
	}
	console.debug(CONSOLE_SEPARATOR);	
};

Your method is much cleaner though and I may use that instead.

Thanks again.

Btw, I'm using frankf's AndOrWriteStore and it works great. Love the complex query work he did. I'm going to add him to my "Supah Star dojo Guru" list. :)

- andy