Changes
Add optional row hook for generating row attributes. It is called after all column hooks. Also improved documentation around BaseTable:create_data_rows_merge_vertical().
row_values[column].rowspan = 1
row_values[column].rowspan = 1
row_values[column].colspan = 1
row_values[column].colspan = 1
end
--check if a row function is defined
if self.row then
--get row attributes
row_values._row = self:row(item)
end
end
end
end
BaseTable.create_data_rows = BaseTable.create_data_rows_plain
BaseTable.create_data_rows = BaseTable.create_data_rows_plain
--create the data rows, merging cells vertically between rows if they contain the same data values.
function BaseTable:create_data_rows_merge_vertical()
function BaseTable:create_data_rows_merge_vertical()
for index, item in ipairs(self._items) do
for index, item in ipairs(self._items) do
end
end
if index > 1 then
if index > 1 then
--This row is not the first row, we have to look at previous rows to determine if we need to merge vertically adjacent cells.
for _, column in ipairs(self._columns) do
for _, column in ipairs(self._columns) do
--Look on a column basis
for i=index-1,1,-1 do
for i=index-1,1,-1 do
--Starting at the previous row and going to the first row.
local previous_row = self._data_rows[i]
local previous_row = self._data_rows[i]
local previous_row_type = type(previous_row) ~= "string"
local previous_row_is_data = type(previous_row) ~= "string"
local previous_cell = previous_row_type and previous_row[column] or false
local previous_cell = previous_row_is_data and previous_row[column] or false
if previous_cell then
if previous_cell then
--The previous row has a cell in the column to compare with
if self.compare_values(row_values[column].values, previous_cell.values) then
if self.compare_values(row_values[column].values, previous_cell.values) then
--The cell values in the column are identical, extend the previous cell's rowspan
--and clear the cell value in the current row to merge them
previous_cell.rowspan = previous_cell.rowspan + 1
previous_cell.rowspan = previous_cell.rowspan + 1
row_values[column] = nil
row_values[column] = nil
else
else
--Values don't match, set rowspan and colspan to 1 to start a new cell.
row_values[column].rowspan = 1
row_values[column].rowspan = 1
row_values[column].colspan = 1
row_values[column].colspan = 1
end
end
--We've found the previous row that has a cell in the column, no need to look further.
break
break
elseif not previous_row_type then
elseif not previous_row_is_data then
--Previous row is not data, so we set rowspan and colspan to one to start a new cell.
row_values[column].rowspan = 1
row_values[column].rowspan = 1
row_values[column].colspan = 1
row_values[column].colspan = 1
end
end
else
else
--This row is the first row, we have no previous rows to look at, so set rowspan and colspan for all cells to 1 to start new cells.
for _, column in ipairs(self._columns) do
for _, column in ipairs(self._columns) do
row_values[column].rowspan = 1
row_values[column].rowspan = 1
row_values[column].colspan = 1
row_values[column].colspan = 1
end
end
end
--check if a row function is defined
if self.row then
--get row attributes
row_values._row = self:row(item)
end
end
end
end