lib/data-table/table.rb in data-table-2.0 vs lib/data-table/table.rb in data-table-2.0.1

- old
+ new

@@ -282,17 +282,24 @@ # ancestors should be an array def render_subtotals(group_header, _group_data = nil, ancestors = nil) html = '' path = ancestors.nil? ? [] : ancestors.dup path << group_header + + is_first_subtotal = true + @subtotal_calculations[path].each_with_index do |group, index| - html << "<tr class='subtotal index_#{index}'>" + next if group.empty? + + html << "<tr class='subtotal index_#{index} #{'first' if is_first_subtotal}'>" @columns.each do |col| value = group[col.name] ? group[col.name].values[0] : nil html << col.render_cell(value) end html << '</tr>' + + is_first_subtotal = false end html end def subtotal(column_name, function = nil, index = 0, &block) @@ -337,11 +344,13 @@ @subtotals.each_with_index do |subtotal_type, index| subtotal_type.each do |subtotal| @collection.each_pair_with_parents(@groupings.count) do |group_name, group_data, parents| path = parents + [group_name] result = calculate(group_data, subtotal[0], subtotal[1], path) - @subtotal_calculations[path][index] ||= {} + (0..index).each do |index| + @subtotal_calculations[path][index] ||= {} + end @subtotal_calculations[path][index][subtotal[0]] = {subtotal[1] => result} end end end end @@ -434,10 +443,12 @@ # if both a block and a function are given then the default aggregate function is called first # then its result is passed into the block for further processing. def total_row(collection, column_name, function = nil, index = nil, &block) function_or_block = function || block f = function && block_given? ? [function, block] : function_or_block - collection[index] = {} if collection[index].nil? + (0..index).each do |index| + collection[index] = {} if collection[index].nil? + end collection[index][column_name] = f end end end