Skip to content

Instantly share code, notes, and snippets.

@ti-ka
Created January 22, 2016 18:38
Show Gist options
  • Save ti-ka/ce1749cfe2d22d75ae46 to your computer and use it in GitHub Desktop.
Save ti-ka/ce1749cfe2d22d75ae46 to your computer and use it in GitHub Desktop.
Sumleft
$("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