OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
## Overview
We currently have two components for implementing a table view:
* a (sortable) `TableComponent`
* a (unsortable, primer based) `BorderBoxTableComponent`
**Sortable table**
<%= embed OpenProject::Deprecated::TablePreview, :default %>
**Border Box Table**
<%= embed OpPrimer::BorderBoxTableComponentPreview, :default %>
For the specifics of that component please have a look at the [BorderBoxTableComponent docs](./border_box_table).
## Anatomy
**Sortable table**
* The Sortable Table results in a standard HTML table with some classes applied for styling.
* If `sortable` is set to true, all sortable column headers are clickable to change the sort order. When a sort is applied, that is indicated via an arrow.
**Border Box Table**
* The BorderBoxTable is based on the `Primer::Beta::BorderBox` with a CSS grid applied inside to align the individual rows and make it look like a table.
## Technical notes
The `BorderBoxTableComponent` is a subclass of the `TableComponent`, so the following notes apply to both components. There are however some additional things to consider, for that please visit the [BorderBoxTableComponent docs](./border_box_table).
To use either table implementation, you need to subclass the following classes onto your own namespace:
- **Regular table:** `TableComponent` and `RowComponent`
- **BorderBox table:** `OpPrimer::BorderBoxTableComponent` and `OpPrimer::BorderBoxRowComponent`
**Columns**
Define the columns of the table as class method:
```ruby
module ModuleA
class TableComponent < ::TableComponent
columns :name, :description, :sort
# ...
end
end
```
**Headers**
Define the headers of the component as a method:
```ruby
module ModuleA
class TableComponent < ::TableComponent
# ...
def headers
[
[:a, { caption: 'Column A' }],
[:b, { caption: 'Column B' }],
[:c, { caption: 'Column C' }]
]
end
# ...
end
end
```
**Actions**
Define the actions in the row component as `button_links`. See the example code:
### Full example
<%= embed OpenProject::Deprecated::TablePreview, :default, panels: %i[source] %>