View Full Version : getSelectedRowIndex :: YAHOO.ext.grid

30 Nov 2006, 9:25 PM

I was modifing one of your XML sample to get a basic understanding of what is going on and ran across the "Click" sending the wrong id when calling "getSelectedRowIndex". Ex: when I click on a row it will return -1. If I clcik it again it returns 0 if it was the first row. Now it I click the second row it returns 0 and then 1 the second time. If I turn the "click" to "dblClick" I don't seem to have the problem. Since this is day 1 looking at your library I am not sure if I am not using your methods correctly or if this is a bug. It seems like there is a "var++" instead of a "++var" somewhere.

I was also was wondering if you had any plans for a CSVDataModel?

var XmlExample = {

init : function(){
var schema = {
tagName: 'Item',
id: 'SchoolID',
fields: ['School', 'State', 'City']
dataModel = new YAHOO.ext.grid.XMLDataModel(schema);

// the DefaultColumnModel expects this blob to define columns. It can be extended to provide
// custom or reusable ColumnModels
var colModel = new YAHOO.ext.grid.DefaultColumnModel([
{header: "School", width: 220, sortable: true},
{header: "State", width: 150, sortable: true},
{header: "City", width: 115, sortable: true}

// create the Grid
var grid = new YAHOO.ext.grid.Grid('school-grid', dataModel, colModel);
grid.autoWidth = true;
grid.autoHeight = true;
grid.on('click', this.showSchoolInfo, grid, true);



showSchoolInfo : function(){
var tmp = this.getDataModel();
var index = this.getSelectedRowIndex();
console.log("Select Row",this.getSelectedRowIndex());
document.getElementById('school-info').innerHTML = "School: " + tmp.getValueAt(index,0);
document.getElementById('school-info').innerHTML += "
State: " + tmp.getValueAt(index,1);
document.getElementById('school-info').innerHTML += "
City: " + tmp.getValueAt(index,2);

YAHOO.ext.EventManager.onDocumentReady(XmlExample.init, XmlExample, true);

1 Dec 2006, 5:24 AM
I think what you are looking for is the rowselect event on the selection model. click is just a raw click event and selection can (and apparently does) occur before the selection.

The base for a text oriented DataModel (like CVS) is in the code but hasn't been implemented. I doubt it would be very difficult.