-
-
Save chadsten/0f296521ba21c1c4e2f035616993232d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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