Example of a table with expression evaluation

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>JSM Test Page</title> <link rel=stylesheet type="text/css" href="../jsm-documentation.css"> <style> body { margin: 10px 0px 0px 10px; background-color:#ffffff; color: #000000; } </style> <script src="jsm.js" type="text/javascript"></script> <link rel=stylesheet type="text/css" href="css/jsm.css"> <script> //your onSaveRow Event function jsmOnSaveRow(table, rowIdx) { var message="Data: \n"; var tds = table.getTds(rowIdx); for (var tdIdx in tds) { var td = tds[tdIdx]; if (td.getMetaData('actionCell') != 'true') message=message+"Table cell is dirty: " + td.isDirty() + " and has value: " + td.getValue() + " - selectFieldValue: " + td.getMetaData("selectFieldValue") + "\n"; } alert(message); table.getRow(rowIdx).setDirty(false); } </script> </head> <body> <div id="myTableContainer"></div> <script> myTable = new JsmTable("myTableContainer", "myTable"); myTable.addColumnName("one", 0).addColumnName("two", 1); myTable.addComparator("two", JsmNumberComparator).addComparator("two", JsmNumberComparator); myTable.setHeaderRow(new JsmTr().addCell(new JsmTh("one").setAttribute("width", "150")).addCell(new JsmTh("two").setAttribute("width", "150")).addCell(new JsmTh("sum").setAttribute("width", "150"))); myTable.addRow(new JsmTr(1).addCell(new JsmTd("4")).addCell(new JsmTd("1")).addCell(new JsmTd("%{Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-1)) + Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-2))}"))); myTable.addRow(new JsmTr(1).addCell(new JsmTd("6")).addCell(new JsmTd("3")).addCell(new JsmTd("%{Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-1)) + Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-2))}"))); myTable.addRow(new JsmTr(2).addCell(new JsmTd("3")).addCell(new JsmTd("32")).addCell(new JsmTd("%{Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-1)) + Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-2))}"))); myTable.addRow(new JsmTr(3).addCell(new JsmTd("2")).addCell(new JsmTd("4")).addCell(new JsmTd("%{Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-1)) + Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-2))}"))); myTable.addRow(new JsmTr(4).addCell(new JsmTd("7")).addCell(new JsmTd("7")).addCell(new JsmTd("%{Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-1)) + Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-2))}"))); myTable.addRow(new JsmTr(5).addCell(new JsmTd("5")).addCell(new JsmTd("2")).addCell(new JsmTd("%{Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-1)) + Number(this.tr.table.getValue(this.tr.getIndex(), this.getIndex()-2))}"))); var footer = new JsmTr(); footer.addCell(new JsmTd("%{var sum=0; for(var rowIdx in this.tr.table.getRows()) {sum+=Number(this.tr.table.getValue(rowIdx, this.getIndex()))} sum;}")); footer.addCell(new JsmTd("%{var sum=0; for(var rowIdx in this.tr.table.getRows()) {sum+=Number(this.tr.table.getValue(rowIdx, this.getIndex()))} sum;}")); footer.addCell(new JsmTd("")); myTable.addFooter(footer); myTable.setSortColumn(-1); myTable.render(); </script> </body> </html>