PDA

View Full Version : Add odd and even column classes to the grid



devol
13 Oct 2006, 6:27 AM
I'm sure there is an Object.extend equivalent in YUI, I'm still using prototype.js so I'm used to ti.
The classes are ygrid-col-even and ygrid-col-odd.



Object.extend(YAHOO.ext.grid.GridView.prototype, {
renderRow : function(dataModel, row, rowIndex, colCount, renderers, dindexes){
for(var colIndex = 0; colIndex < colCount; colIndex++){
var td = document.createElement('span');
td.className = 'ygrid-col ygrid-col-' + colIndex + (colIndex == colCount-1 ? ' ygrid-col-last' : '');
td.className += (colIndex % 2 ? ' ygrid-col-even' : ' ygrid-col-odd'); // Added
td.columnIndex = colIndex;
td.tabIndex = 0;
var span = document.createElement('span');
span.className = 'ygrid-cell-text';
td.appendChild(span);
var val = renderers[colIndex](dataModel.getValueAt(rowIndex, dindexes[colIndex]), rowIndex, colIndex);
if(val == '') val = '';
span.innerHTML = val;
row.appendChild(td);
}
}
});

devol
13 Oct 2006, 6:39 AM
It does break row selection though.

jack.slocum
13 Oct 2006, 7:01 AM
Hidden columns could also create an issue.

devol
13 Oct 2006, 7:18 AM
Ugh didn't think about that. Bad me. Doable, but not that simply.

I did add a "defaultValue" to the numberEditor though. That seems to work ok...