Report abuse

better table generation, powered by Prototype trunk


			
var tbl = new Element("table", { id: "tblExpenses" });
var tblBody = document.createElement("tbody");
var headerRow = document.createElement("tr");
tblBody.appendChild(headerRow);
tbl.appendChild(tblBody);

$w("Description Amount Timestamp").each(function(header) {
  headerRow.appendChild(new Element('th').update(header));
});

var data = result.evalJSON();
console.debug("there are %d results from JSON", data.length)

data.each(function(item) {
  var row = document.createElement("tr");
  var cells = [item.expDesc, item.expAmt, item.expStamp];
  console.debug("inserting %s", cells);

  cells.each(function(cell) {
    row.appendChild(new Element('td').update(cell));
  });
  tblBody.appendChild(row);
});