javascriptで簡単に表計算ってできるの?
私がとった手法の御紹介
表計算ぐらいclientサイドでやった方が
早いんじゃないのー? ってことで, やってみました.
- 前提
-
- column識別のために class="income" および purchase/pretendを付けておく.
- MochiKitを使う(多少簡単に.)
- セル内容はあまり気にしない.
一番時間がかかったのが, forEach文を調べること.
javascriptはそこだけは気にいらない...よなぁ.
例えば、特定のクラスにeventを設定。これはMochiKitで多少楽に.
var iti = iter( getElementsByTagAndClassName( "TD", "income" ) ); var itp = iter( getElementsByTagAndClassName( "TD", "purchase" ) ); var itm = iter( getElementsByTagAndClassName( "TD", "pretend" ) ); forEach( chain( iti, itp, itm ), function( i ){ i.kmoney_type = "income"; connect( "dmy", "ondblclick", i, summery_oncell ); });
結果コードは以下.
code全体:
function kmoneyclass( e ){ if( hasElementClass( e, "income" ) ){ return "income"; } if( hasElementClass( e, "purchase" ) ){ return "purchase"; } if( hasElementClass( e, "pretend" ) ){ return "purchase"; } return undefined; } function summery_oncell( src, e ){ var t = kmoneyclass( src ); var sum = 0.0; var it = null; forEach( it, function( i ){ rsrc = src.parentNode.rowIndex; ri = i.parentNode.rowIndex; if( hasElementClass( i, t ) && rsrc > ri ){ sum += atof( i.innerText ); } }); var o = $( "propetywindow" ); hideElement( o ); o.style.left = e.mouse().page.x - 100; o.style.top = e.mouse().page.y - 30; showElement( o ); prop_inraelyout = False; return False; } function prop_dblclick( src, e ){ hideElement( e ); return False; } function prop_mouseover(){ prop_inraelyout = False; } function prop_mouseout(){ prop_inraelyout = True; // timmer set to ... connect( "dmy", "", "prop_realyout" ); return False; } function prop_realyout(){ if( !prop_inraelyout ){ return False; } prop_inraelyout = False; var o = $( "propertywindow" ); hideElement( o ); return False; } var iti = iter( getElementsByTagAndClassName( "TD", "income" ) ); var itp = iter( getElementsByTagAndClassName( "TD", "purchase" ) ); var itm = iter( getElementsByTagAndClassName( "TD", "pretend" ) ); forEach( chain( iti, itp, itm ), function( i ){ i.kmoney_type = "income"; connect( "dmy", "ondblclick", i, summery_oncell ); }); var prop_inraelyout = False; connect( "propertywindow", "onmouseout", "prop_mouseout" ); connect( "propertywindow", "onmouseover", "prop_mouseover" ); connect( "propertywindow", "ondblclick", "prop_dblclick" ); DIV( {"id": "propertywindow", "class": "floatdialog", "style": { "display": "none" }});
コメント
Comments powered by Disqus