Skip to content

Instantly share code, notes, and snippets.

@chadsten
Forked from anonymous/stuff.js
Last active May 23, 2016 00:27
Show Gist options
  • Save chadsten/0f296521ba21c1c4e2f035616993232d to your computer and use it in GitHub Desktop.
Save chadsten/0f296521ba21c1c4e2f035616993232d to your computer and use it in GitHub Desktop.
<script>
$(".original tbody").on( "click", "tr", function() {
var row_id = ($(this).attr('class').split(' ')[0]);
if ($('.selected .' + row_id).length > 0) {
// do nothing, probably should use .not() up there
} else {
$(this).addClass('cloned').clone().prependTo($('.selected'));
}
calculate();
})
$(".selected tbody").on( "click", "tr", function() {
var row_id = ($(this).attr('class').split(' ')[0]);
$('.original .' + row_id).removeClass('cloned');
$(this).remove();
calculate();
})
var calculate = function () {
var sum = $('.selected tr td:nth-child(2)').toArray().map(function (td) {
return $(td).text();
}).reduce(function (sum, i) {
return sum + parseInt(i);
}, 0);
$('.total').text(sum);
};
var t = $('table');
var c = $('.column');
calculate();
$("#original").tablesorter( {sortList: [[1,0]]} );
$("#selected").tablesorter();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment