On Tue, Apr 29, 2008 at 6:13 PM, Mike van Lammeren <[EMAIL PROTECTED]> wrote: > var tableRows = tableElement.down().childElements();
What is the purpose of down() in this case? Is it to get to the tbody? To avoid fetching every row in the table, you could get away with using a child selector to only fetch the row you are looking for. tableElement.select('tr:nth-child(' + rowIndex + ')'); You'd have to check if there was a thead or tfoot though, since this would be higher up in the DOM than the tbody. Pretty handy little extension though :) -justin On Tue, Apr 29, 2008 at 6:13 PM, Mike van Lammeren <[EMAIL PROTECTED]> wrote: > > Here are some handy extensions to select table rows and columns: > > var TableUtils = { > /** > * @param element a table element > * @param integer the requested row > * @return array an array of table cell elements > **/ > getRowCells: function(tableElement, rowIndex){ > tableElement = $(tableElement); // extend the table element > var tableRows = tableElement.down().childElements(); > if(tableRows[rowIndex]) > { > return (tableRows[rowIndex]).descendants(); > } > return []; > }, > /** > * @param element a table element > * @param integer the requested row > * @return array an array of table cell elements > **/ > getColumnCells: function(tableElement, columnIndex){ > tableElement = $(tableElement); // extend the table element > var columnCells = []; > var tableRows = tableElement.down().childElements(); > tableRows.each(function(trEl, index){ // loop over each table > row > var tCells = trEl.descendants(); // table cells in row > if(tCells[columnIndex]) > { > columnCells.push($(tCells[columnIndex])); // extend > each tableElement > } > }); > return columnCells; > } > } > Element.addMethods('table', TableUtils); > > > Example calls: > $('testTable').getColumnCells(1).invoke('fade'); > $('testTable').getRowCells(1).invoke('fade'); > > What do you think? Is there a faster/more elegant solution? > > Mike van Lammeren > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---