DataGrid: build cells, rows and columns
Cells referenced by x,y (like spreadsheet)
Features:
- Cells with conditional formatting, e.g. cell is red is value over threshold
- Cells with formula, e.g. SUM(A5-A6)
Table has default cell attributes, e.g. height/width
template_cells = []
template_cells << BasicCell.new(name: ‘Name’, key: ‘name’)
template_cells << BasicCell.new(name: ‘Ref’, key: ‘ref’)
template_cells << DateCell.new(name: ‘start_date’, format: ‘%d/%m/%Y’, key: ‘start_date’)
studies.each do |study|
table.rows.add |row|
template_cells.each do |template_cell|
cell = template_cell.dup
cell.value = study.send(cell.key)
row.cells << cell
end
end
end
build a table by creating some template cells (which represent a row). For each study duplicate the cells and populate them with data from the study.
feed table in to a HAML template.
BasicCell.new(key: 'organisation.name')
e.g. Display a formatted date which is a link
LinkedCell.new(cell: DateCell.new(key: started_on), url: '...')