Skip to content

Commit

Permalink
Fixed issue #19290: Wrong Row Total in Array (Texts) (#3664)
Browse files Browse the repository at this point in the history
Co-authored-by: lapiudevgit <devgit@lapiu.biz>
  • Loading branch information
gabrieljenik and lapiudevgit committed Jan 31, 2024
1 parent 11b1240 commit dff6339
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
30 changes: 17 additions & 13 deletions assets/packages/questions/arraynumeric/scripts/array-totalsum.js
Expand Up @@ -50,21 +50,25 @@ function sumTable(element) {
});

// Sum all columns
// First get number of columns (only visible and enabled inputs)
var visibleRows = table.find('tbody tr:visible');
var iColumnNum = visibleRows.first().find('input:enabled:visible').length;
//Get An array of jQuery Objects
var $iRow = table.find('tr');
//Iterate through the columns
for (var i = 1; i <= iColumnNum; i++) {
var sum = new Decimal(0);
$iRow.each(function () {
var item = $($(this).find('td').get((i - 1))).find('input:enabled:visible'),
val = normalizeValue($(item).val());
//sum the values
sum = sum.plus(val);
});
$($iRow.last().find('td.total').get((i - 1))).find('input:disabled').val(formatValue(sum)).trigger('change').trigger('keyup').trigger('keydown');
// If Totals are enabled for columns, there is a row with class "total"
var lastRow = $iRow.last();
if (lastRow.hasClass('total')) {
// First get number of columns (only visible and enabled inputs)
var visibleRows = table.find('tbody tr:visible');
var iColumnNum = visibleRows.first().find('input:enabled:visible').length;
//Iterate through the columns
for (var i = 1; i <= iColumnNum; i++) {
var sum = new Decimal(0);
$iRow.each(function () {
var item = $($(this).find('td').get((i - 1))).find('input:enabled:visible'),
val = normalizeValue($(item).val());
//sum the values
sum = sum.plus(val);
});
$(lastRow.find('td.total').get((i - 1))).find('input:disabled').val(formatValue(sum)).trigger('change').trigger('keyup').trigger('keydown');
}
}

// Grand total
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dff6339

Please sign in to comment.