Created
January 22, 2016 18:38
-
-
Save ti-ka/ce1749cfe2d22d75ae46 to your computer and use it in GitHub Desktop.
Sumleft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("body").on("click", "td", function(){ | |
$(this).html(parse($(this).html(), this)); | |
}) | |
function parse(str, _td){ | |
return str.replace("=SUMLEFT()", sumLeft(_td)) | |
} | |
function sumLeft(_td){ | |
_td = $(_td); | |
sum = 0; | |
while(_td.prev().is("td")){ | |
sum += parseFloat(_td.prev().html()); | |
if(_td && _td.prev()){ | |
_td = _td.prev(); | |
} else { | |
break; | |
} | |
} | |
return sum; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment