Skip to content

Instantly share code, notes, and snippets.

@webdood
Created May 18, 2010 18:57
Show Gist options
  • Save webdood/405371 to your computer and use it in GitHub Desktop.
Save webdood/405371 to your computer and use it in GitHub Desktop.
////////////////////////////////////////////////////////////////////////////////
// EnsureMinimumNumberOfRows(element, params) - ensures a table will have a minimum
// ========================================== number of visible rows.
// Supported params are:
// numberOfRows - gives the minimum number of rows that will appear
// rowHeight - height, in pixels for added rows
// *NOTE: Does not support empty tables
////////////////////////////////////////////////////////////////////////////////
function EnsureMinimumNumberOfRows(element, params) {
var minimumNumberOfRows = params.numberOfRows || 10, // default minimumNumberOfRows is 10
rowHeight = params.rowHeight || 30, // default rowHeight (for new rows) is 30px
oTable = $(element).select('div.resultList table')[0], // Get the first element as $(element).select returns an array
numberOfRowsToInsert = minimumNumberOfRows - oTable.rows.length + 1;
if (numberOfRowsToInsert > 0) {
var clonedRow = oTable.rows[ oTable.rows.length - 1 ]
clonedCells = clonedRow.getElementsByTagName('td');
for (var i=0;i<numberOfRowsToInsert;i++) {
var oRow = document.createElement("TR");
for (j=0;j<clonedCells.length;j++) {
var oCell = clonedCells[j].cloneNode(false);
oCell.style.height = rowHeight + "px";
oCell.appendChild( document.createTextNode("\u00a0") );
oRow.appendChild(oCell);
}
oTable.appendChild( oRow );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment