| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Use table size "sm" when data density is a priority. Smaller row height enables the user to view more data without the need for scrolling.
Table can leverage the max-width property. Learn more on our Max Width Global Props page.
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Use table size "md" to add padding around each row to increase reading comfortability.
<%= pb_rails("table", props: { size: "md" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Use table size "lg" to add padding around each row to maximize reading comfortability.
<%= pb_rails("table", props: { size: "lg"} ) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
React: Use sticky on a table to allow the table header to be fixed in place when the user scrolls up and down on the page.
Rails: Pass sticky: true to props.
If the table header is not sticking in the right place you will need to pass a inline top style to the thead.
React Example: <thead style={{ top: "-16px" }}>
Rails Example: <thead style="top: -16px">
Sticky may not work if any parent/ancestor of the sticky element has any of the overflow properties set. Additionally, specifying a height on the overflowing container provides measurement for this feature to work properly. In some cases, it may be necessary to set the same parent/ancestor container to position: static as well.
<%= pb_rails("table", props: { sticky: true }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7 | Column 8 | Column 9 | Column 10 | Column 11 | Column 12 | Column 13 | Column 14 | Column 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
The sticky_left_column prop expects an array of the column data-sticky-ids you want to be sticky. Make sure to add the corresponding data-sticky-id to the <th> and <td>.
Please ensure that unique data-sticky-ids are used for all columns across multiple tables. Using the same columns data-sticky-ids on multiple tables can lead to issues when using the sticky_left_column.
<%= pb_rails("table", props: { size: "md", responsive: "scroll", sticky_left_column: ["1", "2", "3"] }) do %> <thead> <tr> <th data-sticky-id="1">Column 1</th> <th data-sticky-id="2">Column 2</th> <th data-sticky-id="3">Column 3</th> <th>Column 4</th> <th>Column 5</th> <th>Column 6</th> <th>Column 7</th> <th>Column 8</th> <th>Column 9</th> <th>Column 10</th> <th>Column 11</th> <th>Column 12</th> <th>Column 13</th> <th>Column 14</th> <th>Column 15</th> </tr> </thead> <tbody> <tr> <td data-sticky-id="1">Value 1</td> <td data-sticky-id="2">Value 2</td> <td data-sticky-id="3">Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td>Value 13</td> <td>Value 14</td> <td>Value 15</td> </tr> <tr> <td data-sticky-id="1">Value 1</td> <td data-sticky-id="2">Value 2</td> <td data-sticky-id="3">Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td>Value 13</td> <td>Value 14</td> <td>Value 15</td> </tr> <tr> <td data-sticky-id="1">Value 1</td> <td data-sticky-id="2">Value 2</td> <td data-sticky-id="3">Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td>Value 13</td> <td>Value 14</td> <td>Value 15</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7 | Column 8 | Column 9 | Column 10 | Column 11 | Column 12 | Column 13 | Column 14 | Column 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
The sticky_right_column prop works in the same way as the above sticky_left_column prop. It expects an array of the column data-sticky-ids you want to be sticky. Make sure to add the corresponding data-sticky-id to the <th> and <td>.
Please ensure that unique data-sticky-ids are used for all columns across multiple tables. Using the same columns data-sticky-ids on multiple tables can lead to issues when using the sticky_right_column prop.
<%= pb_rails("table", props: { size: "md", responsive: "scroll", sticky_right_column: ["13", "14", "15"] }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> <th>Column 6</th> <th>Column 7</th> <th>Column 8</th> <th>Column 9</th> <th>Column 10</th> <th>Column 11</th> <th>Column 12</th> <th data-sticky-id="13">Column 13</th> <th data-sticky-id="14">Column 14</th> <th data-sticky-id="15">Column 15</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td data-sticky-id="13">Value 13</td> <td data-sticky-id="14">Value 14</td> <td data-sticky-id="15">Value 15</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td data-sticky-id="13">Value 13</td> <td data-sticky-id="14">Value 14</td> <td data-sticky-id="15">Value 15</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td data-sticky-id="13">Value 13</td> <td data-sticky-id="14">Value 14</td> <td data-sticky-id="15">Value 15</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7 | Column 8 | Column 9 | Column 10 | Column 11 | Column 12 | Column 13 | Column 14 | Column 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | Value 6 | Value 7 | Value 8 | Value 9 | Value 10 | Value 11 | Value 12 | Value 13 | Value 14 | Value 15 |
The sticky_left_column and sticky_right_column props can be used together on the same table as needed.
Please ensure that unique data-sticky-ids are used for all columns across multiple tables. Using the same columns data-sticky-ids on multiple tables can lead to issues when using props.
<%= pb_rails("table", props: { size: "md", responsive: "scroll", sticky_left_column: ["a"], sticky_right_column: ["b"] }) do %> <thead> <tr> <th data-sticky-id="a">Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> <th>Column 6</th> <th>Column 7</th> <th>Column 8</th> <th>Column 9</th> <th>Column 10</th> <th>Column 11</th> <th>Column 12</th> <th>Column 13</th> <th>Column 14</th> <th data-sticky-id="b">Column 15</th> </tr> </thead> <tbody> <tr> <td data-sticky-id="a">Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td>Value 13</td> <td>Value 14</td> <td data-sticky-id="b">Value 15</td> </tr> <tr> <td data-sticky-id="a">Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td>Value 13</td> <td>Value 14</td> <td data-sticky-id="b">Value 15</td> </tr> <tr> <td data-sticky-id="a">Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <td>Value 6</td> <td>Value 7</td> <td>Value 8</td> <td>Value 9</td> <td>Value 10</td> <td>Value 11</td> <td>Value 12</td> <td>Value 13</td> <td>Value 14</td> <td data-sticky-id="b">Value 15</td> </tr> </tbody> <% end %>
|
Territory
|
Full Name
|
Age
|
Job Title | |
|---|---|---|---|---|
| North | John | Doe | 30 | Engineer |
| South | Alice | Smith | 28 | Designer |
| East | Mike | Johnson | 35 | Manager |
| West | Sarah | Brown | 29 | Developer |
| Central | David | Wilson | 32 | Analyst |
The table_header subcomponent creates <th> elements and optionally accepts:
colspan (number) for setting column spansort_menu accepts sort options as an array of item objects.
presence of sort_menu enables the sort link within the headersort_dropdown (boolean) optionally declares that (true) clicking a header's sort link opens a dropdown of sort options, or (false) each sort link click cycles through available sort_menu items in the order they are passed
colspan will render sort options within a dropdown by default, without requiring sort_dropdown explicitly. Alternatively, the default sort dropdown can be prevented on headers with colspan by setting sort_dropdown: false, which reverts the column to sorting to multi-click default (each click of the sort link cycles through the available sort_menu items in the order they are passed)id (string) is required for headers that have a dropdown (for popover reference); otherwise they are optionalThis example uses a custom sort method that may need to be modified or replaced within your project.
<%# Example data for demonstration purposes %> <% data_rows = [ { 'territory' => 'North', 'firstname' => 'John', 'lastname' => 'Doe', 'age' => 30, 'job' => 'Engineer' }, { 'territory' => 'South', 'firstname' => 'Alice', 'lastname' => 'Smith', 'age' => 28, 'job' => 'Designer' }, { 'territory' => 'East', 'firstname' => 'Mike', 'lastname' => 'Johnson', 'age' => 35, 'job' => 'Manager' }, { 'territory' => 'West', 'firstname' => 'Sarah', 'lastname' => 'Brown', 'age' => 29, 'job' => 'Developer' }, { 'territory' => 'Central', 'firstname' => 'David', 'lastname' => 'Wilson', 'age' => 32, 'job' => 'Analyst' } ] %> <%# Example sort method for demonstration purposes %> <% if params["sort"] %> <% sort_param = params["sort"].gsub(/_(asc|desc)\z/, "") %> <% sort_direction = params["sort"].end_with?("_asc") ? 1 : -1 %> <% data_rows.sort! do |a, b| value_a = a[sort_param] value_b = b[sort_param] value_a = value_a.to_i if value_a.is_a?(String) && value_a.match?(/^\d+$/) value_b = value_b.to_i if value_b.is_a?(String) && value_b.match?(/^\d+$/) sort_direction * (value_a <=> value_b) end %> <% end %> <%= pb_rails("table", props: { data_table: true, vertical_border: true, id: "table-header" } ) do %> <thead> <tr> <%= pb_rails("table/table_header", props: { text: "Territory", id: "territory", sort_menu: [ { item: "Territory", link: "?sort=territory_asc#table-header", active: params["sort"] == "territory_asc", direction: "asc" }, { item: "Territory", link: "?sort=territory_desc#table-header", active: params["sort"] == "territory_desc", direction: "desc" } ], }) %> <%= pb_rails("table/table_header", props: { id: "name", text: "Full Name", colspan: 2, sort_menu: [ { item: "First Name", link: "?sort=firstname_desc#table-header", active: params["sort"] == "firstname_desc", direction: "desc" }, { item: "First Name", link: "?sort=firstname_asc#table-header", active: params["sort"] == "firstname_asc", direction: "asc" }, { item: "Last Name", link: "?sort=lastname_desc#table-header", active: params["sort"] == "lastname_desc", direction: "desc" }, { item: "Last Name", link: "?sort=lastname_asc#table-header", active: params["sort"] == "lastname_asc", direction: "asc" } ], }) %> <%= pb_rails("table/table_header", props: { text: "Age", id: "age", sort_menu: [ { item: "Age Descending", link: "?sort=age_desc#table-header", active: params["sort"] == "age_desc", direction: "desc" }, { item: "Age Ascending", link: "?sort=age_asc#table-header", active: params["sort"] == "age_asc", direction: "asc" } ], }) %> <%= pb_rails("table/table_header", props: { text: "Job Title" }) %> </tr> </thead> <tbody> <% data_rows.each do |row| %> <tr> <% row.each do |key, value| %> <%= pb_rails("background", props: { background_color: (params["sort"] && params["sort"].start_with?(key) ? "info_subtle" : "card_light"), text_align: (value.is_a?(Integer) ? "right" : ""), tag: "td" }) do %> <%= value %> <% end %> <% end %> </tr> <% end %> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Pass our text_align global prop to any table/table_row subcomponent to change the text alignment of all cells within that row.
The header/ first row is the default, followed by the second row being centered, and then the last row shifted to the right.
<%= pb_rails("table") do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <%= pb_rails("table/table_row", props: { text_align: "center" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <%= pb_rails("table/table_row", props: { text_align: "right" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Rating | Money |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | 3 | $57.32 |
| Value 1 | Value 2 | Value 3 | 2 | $5,657.08 |
| Value 1 | Value 2 | Value 3 | 4 | $358.77 |
Pass our text_align global prop to any table/table_cell subcomponent to change the text alignment of individual cells, or apply this prop persistently to align entire columns.
In the table above the "Rating" column contents is centered and the "Money" column contents is right aligned.
<%= pb_rails("table") do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Rating", text_align: "center" }) %> <%= pb_rails("table/table_header", props: { text: "Money", text_align: "right" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "3", text_align: "center" }) %> <%= pb_rails("table/table_cell", props: { text: "$57.32", text_align: "right" }) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "2", text_align: "center" }) %> <%= pb_rails("table/table_cell", props: { text: "$5,657.08", text_align: "right" }) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "4", text_align: "center" }) %> <%= pb_rails("table/table_cell", props: { text: "$358.77", text_align: "right" }) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
|
Value 1a
Value 1a Value 1a | Value 2a | Value 3a | Value 4a | Value 5a |
|
Value 1b
Value 1b Value 1b | Value 2b | Value 3b | Value 4b | Value 5b |
|
Value 1c
Value 1c Value 1c | Value 2c | Value 3c | Value 4c | Value 5c |
Pass our vertical_align global prop to any table/table_row subcomponent to change the vertical alignment of all cells within that row.
<%= pb_rails("table") do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1" }) %> <%= pb_rails("table/table_header", props: { text: "Column 2" }) %> <%= pb_rails("table/table_header", props: { text: "Column 3" }) %> <%= pb_rails("table/table_header", props: { text: "Column 4" }) %> <%= pb_rails("table/table_header", props: { text: "Column 5" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell") do %> Value 1a <br /> Value 1a <br /> Value 1a <% end %> <%= pb_rails("table/table_cell", props: { text: "Value 2a" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3a" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4a" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5a" }) %> <% end %> <%= pb_rails("table/table_row", props: { vertical_align: "middle" }) do %> <%= pb_rails("table/table_cell") do %> Value 1b <br /> Value 1b <br /> Value 1b <% end %> <%= pb_rails("table/table_cell", props: { text: "Value 2b" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3b" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4b" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5b" }) %> <% end %> <%= pb_rails("table/table_row", props: { vertical_align: "bottom" }) do %> <%= pb_rails("table/table_cell") do %> Value 1c <br /> Value 1c <br /> Value 1c <% end %> <%= pb_rails("table/table_cell", props: { text: "Value 2c" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3c" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4c" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5c" }) %> <% end %> <% end %> <% end %>
| | Price |
|---|---|
| Total |
$12 $46 $25 ------- $83 |
| Espresso Drinks | Ingredients |
|---|---|
| Cappuccino |
Espresso Steamed Milk Milk Foam |
| Macchiato |
Espresso Steamed Milk |
| Mocha |
Espresso Hot Chocolate Steamed Milk |
Pass our vertical_align global prop to any table/table_cell subcomponent to change the text alignment of individual cells, or apply this prop persistently to align entire columns.
The first table shifts "Total" down, whereas the second table shifts the "Espresso Drinks" column contents up.
<%= pb_rails("table") do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: " " }) %> <%= pb_rails("table/table_header", props: { text: "Price" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Total", vertical_align: "bottom" }) %> <%= pb_rails("table/table_cell") do %> $12<br/> $46<br/> $25<br/> -------<br/> $83 <% end %> <% end %> <% end %> <% end %> <br/> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Espresso Drinks" }) %> <%= pb_rails("table/table_header", props: { text: "Ingredients" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Cappuccino", vertical_align: "top" }) %> <%= pb_rails("table/table_cell") do %> Espresso<br/> Steamed Milk<br/> Milk Foam <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Macchiato", vertical_align: "top" }) %> <%= pb_rails("table/table_cell") do %> Espresso<br/> Steamed Milk <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Mocha", vertical_align: "top" }) %> <%= pb_rails("table/table_cell") do %> Espresso<br/> Hot Chocolate<br/> Steamed Milk <% end %> <% end %> <% end %> <% end %>
| Product Colors | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Product 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Product 2 | Value 2 | Value 3 | Value 4 | Value 5 |
| Product 3 | Value 2 | Value 3 | Value 4 | Value 5 |
| None | Value 2 | Value 3 | Value 4 | Value 5 |
| Status Colors | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Success | Value 2 | Value 3 | Value 4 | Value 5 |
| Warning | Value 2 | Value 3 | Value 4 | Value 5 |
| Error | Value 2 | Value 3 | Value 4 | Value 5 |
| None | Value 2 | Value 3 | Value 4 | Value 5 |
| Cateogry Colors | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Category Color 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Category Color 2 | Value 2 | Value 3 | Value 4 | Value 5 |
| Category Color 3 | Value 2 | Value 3 | Value 4 | Value 5 |
| None | Value 2 | Value 3 | Value 4 | Value 5 |
Side highlight can take product, status, and category colors. To view full list of colors, visit token colors.
Note: Only use category colors for categories. Do not mix it with product or status colors.
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Product Colors</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <%= pb_rails("table/table_row", props: { side_highlight_color: "product_1_highlight" }) do %> <td>Product 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "product_2_highlight" }) do %> <td>Product 2</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "product_3_highlight" }) do %> <td>Product 3</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "none" }) do %> <td>None</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> </tbody> <% end %> <br/> <%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Status Colors</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <%= pb_rails("table/table_row", props: { side_highlight_color: "success" }) do %> <td>Success</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "warning" }) do %> <td>Warning</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "error" }) do %> <td>Error</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "none" }) do %> <td>None</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> </tbody> <% end %> <br/> <%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Cateogry Colors</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <%= pb_rails("table/table_row", props: { side_highlight_color: "category_1" }) do %> <td>Category Color 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "category_2" }) do %> <td>Category Color 2</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "category_3" }) do %> <td>Category Color 3</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> <%= pb_rails("table/table_row", props: { side_highlight_color: "none" }) do %> <td>None</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> <% end %> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
<%= pb_rails("table", props: { size: "md", container: false}) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
<%= pb_rails("table", props: { size: "md", disable_hover: true }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
<%= pb_rails("table", props: { size: "md"}) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
| Value 1 Value 1 Value 1 |
Value 2 | Value 3 Value 3 |
Value 4 | Value 5 |
<%= pb_rails("table", props: { size: "md", single_line: true }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1<br/>Value 1<br/>Value 1</td> <td>Value 2</td> <td>Value 3<br/>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Tighter spacing in first- and last-child cells of each row for data-heavy tables.
<%= pb_rails("table", props: { data_table: true }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
<%= pb_rails("title", props: { size: 4, text: "Not Responsive" }) %> <%= pb_rails("table", props: { responsive: "none" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %> <br> <%= pb_rails("title", props: { size: 4, text: "Collapse Mobile" }) %> <%= pb_rails("table", props: { collapse: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %> <br> <%= pb_rails("title", props: { size: 4, text: "Collapse Tablet" }) %> <%= pb_rails("table", props: { collapse: "md" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %> <br> <%= pb_rails("title", props: { size: 4, text: "Collapse Desktop" }) %> <%= pb_rails("table", props: { collapse: "lg" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 |
If there is one button on each row of the table, ideally, it should use the secondary variant and be placed at the end of the row
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th></th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"><%= pb_rails("button", props: { text: "Action", variant: "secondary" }) %></td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"><%= pb_rails("button", props: { text: "Action", variant: "secondary" }) %></td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"><%= pb_rails("button", props: { text: "Action", variant: "secondary" }) %></td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 |
If there are two actions on each of the row, one should ideally one should use the secondary variant and the other use the link variant. The button using the secondary variant should be placed at the end.
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th></th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("button", props: { text: "Tertiary Action", variant: "link", padding_left: "none" }) %> <%= pb_rails("button", props: { text: "Secondary Action", variant: "secondary" }) %> </td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("button", props: { text: "Tertiary Action", variant: "link", padding_left: "none" }) %> <%= pb_rails("button", props: { text: "Secondary Action", variant: "secondary" }) %> </td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("button", props: { text: "Tertiary Action", variant: "link", padding_left: "none" }) %> <%= pb_rails("button", props: { text: "Secondary Action", variant: "secondary" }) %> </td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 | |
If there are more than two actions on each row, then they should be contained in secondary circle icon button with the ellipsis-h icon (horizontal ellipsis) at the end of the row
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th></th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "ellipsis-h" }) %> </td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "ellipsis-h" }) %> </td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "ellipsis-h" }) %> </td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 4 | Value 5 |
If the button is towards the middle of the table, it should likely use button variant link
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td><%= pb_rails("button", props: { text: "Action", variant: "link", padding_left: "none" }) %></td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td><%= pb_rails("button", props: { text: "Action", variant: "link", padding_left: "none" }) %></td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td><%= pb_rails("button", props: { text: "Action", variant: "link", padding_left: "none" }) %></td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 |
|
| Value 1 | Value 2 | Value 3 | Value 4 |
|
| Value 1 | Value 2 | Value 3 | Value 4 |
|
Icon buttons are great to use if space is limited. If the icon isn’t VERY self explanatory (for example pencil/pen for edit, trashcan for delete) then it should use a tooltip explaining what the action does. The tooltip shouldn’t be longer than a few words and essentially serves as a replacement for what the button would say if it weren’t an icon
<%= pb_rails("table", props: { size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th></th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td> <%= pb_rails("flex", props: { justify: "end" }) do %> <%= pb_rails("body", props: {classname: "flex-item"}) do %> <%= pb_rails("circle_icon_button", props: { variant: "link", icon: "pencil" }) %> <% end %> <%= pb_rails("body", props: {classname: "flex-item"}) do %> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "trash-alt" }) %> <% end %> <% end %> </td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td> <%= pb_rails("flex", props: { justify: "end" }) do %> <%= pb_rails("body", props: {classname: "flex-item"}) do %> <%= pb_rails("circle_icon_button", props: { variant: "link", icon: "pencil" }) %> <% end %> <%= pb_rails("body", props: {classname: "flex-item"}) do %> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "trash-alt" }) %> <% end %> <% end %> </td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"> <%= pb_rails("flex", props: { justify: "end" }) do %> <%= pb_rails("body", props: {classname: "flex-item"}) do %> <%= pb_rails("circle_icon_button", props: { variant: "link", icon: "pencil" }) %> <% end %> <%= pb_rails("body", props: {classname: "flex-item"}) do %> <%= pb_rails("circle_icon_button", props: { variant: "secondary", icon: "trash-alt" }) %> <% end %> <% end %> </td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 |
|---|---|---|
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Column 1 | Column 2 | Column 3 |
|---|---|---|
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
| Value 1 | Value 2 | Value 3 |
<%= pb_rails("table", props: { size: "sm", margin_bottom: "lg" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> <%= pb_rails("background", props: { background_color: "error_subtle", tag: "tr" }) do %> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <% end %> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> <%= pb_rails("background", props: { background_color: "warning_subtle", tag: "tr" }) do %> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <% end %> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> </tbody> <% end %> <%= pb_rails("table", props: { size: "sm", margin_bottom: "lg" }) do %> <colgroup> <%= pb_rails("background", props: { background_color: "error_subtle", tag: "col" }) %> <%= pb_rails("background", props: { background_color: "info_subtle", tag: "col" }) %> <%= pb_rails("background", props: { background_color: "warning_subtle", tag: "col" }) %> </colgroup> <thead> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
<%= pb_rails("table", props: { size: "sm", vertical_border: true }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Optionally pass the striped (boolean, defaults to false) prop to set odd rows to a contrasting background color. This helps with readability on larger tables with lots of data.
<%= pb_rails("table", props: { size: "sm", striped: true }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
You can optionally build your table using our sub-components, which map to their respective html table elements:
table_head = thead
table_body = tbody
table_row = tr
table_header = th
table_cell = td
<%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <% end %> <% end %>
Optionally build your table with divs by passing div to the tag prop of all* your sub-components.
*NOTE: The tag prop defaults to table, which returns html elements. If divs are desired, sub-components must be used and all table elements, including the initial kit call, must use div as their tag in order for the table to render properly.
<%= pb_rails("table", props: { size: "sm", tag:"div" }) do %> <%= pb_rails("table/table_head", props: {tag:"div"}) do %> <%= pb_rails("table/table_row", props: {tag:"div"}) do %> <%= pb_rails("table/table_header", props: { text: "Column 1", tag:"div"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2", tag:"div"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3", tag:"div"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4", tag:"div"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5", tag:"div"}) %> <% end %> <% end %> <%= pb_rails("table/table_body", props: {tag:"div"}) do %> <%= pb_rails("table/table_row", props: {tag:"div"}) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5", tag:"div"}) %> <% end %> <%= pb_rails("table/table_row", props: {tag:"div"}) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5", tag:"div"}) %> <% end %> <%= pb_rails("table/table_row", props: {tag:"div"}) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4", tag:"div"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5", tag:"div"}) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 | |
| Value 1 | Value 2 | Value 3 | Value 4 |
Pass any of our spacing tokens to the outerPadding / outer_padding prop to customize a table's outer padding (both the left padding of the first column and the right padding of the last column).
<%= pb_rails("table", props: { outer_padding: "sm", size: "sm" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th></th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"><%= pb_rails("button", props: { text: "Action", variant: "secondary" }) %></td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"><%= pb_rails("button", props: { text: "Action", variant: "secondary" }) %></td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td align="right"><%= pb_rails("button", props: { text: "Action", variant: "secondary" }) %></td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
|
Nested content inside a Table Row
| |||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
The collapsible prop can be used on any Table Row to add a collapsible area. Use the additional collapsible_content prop to add any content to the collapsible Row.
Please be aware that you will need to pass in an id to any table rows you want to be collapsible. Make sure every id is unique if you are using multipe collapsibles.
<% content = capture do %> <%= pb_rails("card", props: { border_none: true, border_radius: "none", padding: "md" }) do %> <%= pb_rails("body", props: { text: "Nested content inside a Table Row" }) %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <%= pb_rails("table/table_header", props: { text: ""}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: true, id: "1" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right"}) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
|
Nested content inside a Table Row
| |||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
The collapsible prop can be used on any Table Row to add a collapsible area. Use the additional collapsible_content prop to add any content to the collapsible Row.
Please be aware that you will need to pass in an id to any table rows you want to be collapsible. Make sure every id is unique if you are using multipe collapsibles.
Follow this example to make the icons dynamic following the state of the collapsible.
<% content = capture do %> <%= pb_rails("card", props: { border_none: true, border_radius: "none", padding: "md" }) do %> <%= pb_rails("body", props: { text: "Nested content inside a Table Row" }) %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <%= pb_rails("table/table_header", props: { text: ""}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: true, id: "11" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1", html_options: { onclick: "toggleArrows()" }}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2", html_options: { onclick: "toggleArrows()" }}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3", html_options: { onclick: "toggleArrows()" }}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4", html_options: { onclick: "toggleArrows()" }}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5", html_options: { onclick: "toggleArrows()" }}) %> <%= pb_rails("table/table_cell", props: { text_align: "right", html_options: { onclick: "toggleArrows()" }}) do %> <%= pb_rails("icon", props: {id: "chevron-icon-down", icon: "chevron-down", fixed_width: true, color: "primary" }) %> <%= pb_rails("icon", props: {id: "chevron-icon-up", icon: "chevron-up", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <% end %> <% end %> <script> const downArrow = document.getElementById("chevron-icon-down"); const upArrow = document.getElementById("chevron-icon-up"); upArrow.style.display = upArrow.style.display === 'none' ? 'inline-block' : 'none'; function toggleArrows() { if (downArrow) { downArrow.style.display = downArrow.style.display === 'none' ? 'inline-block' : 'none'; } if (upArrow) { upArrow.style.display = upArrow.style.display === 'none' ? 'inline-block' : 'none'; } } </script>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
|
Nested content inside a Table Row
| |||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
|
Nested content inside a Table Row
| |||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
|
Nested content inside a Table Row
|
When using the collapsible prop, the default functionality is that the entire Row will be clickable to toggle the Row. To limit the click event to a specific Table Cell, you can use the toggle_cell_id prop to pass in the id of the Cell you want to use as the trigger.
NOTE: toggle_cell_id and the id on the Cell you want to use as the trigger MUST be the same. Please also be aware that you will need to pass in an id to any Table Rows you want to be collapsible. Make sure every id is unique if you are using multipe collapsibles.
<% content = capture do %> <%= pb_rails("card", props: { border_none: true, border_radius: "none", padding: "md" }) do %> <%= pb_rails("body", props: { text: "Nested content inside a Table Row" }) %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <%= pb_rails("table/table_header", props: { text: ""}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: true, toggle_cell_id: "cell-1", id: "5" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right", id: "cell-1", cursor: "pointer" }) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: true, toggle_cell_id: "cell-2", id: "6" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right", id: "cell-2", cursor: "pointer" }) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: true, toggle_cell_id: "cell-3", id: "7" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right", id: "cell-3", cursor: "pointer" }) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
|
Expanded Custom Layout
| |||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
<% content = capture do %> <%= pb_rails("card", props: { border_none: true, border_radius: "none", padding: "md" }) do %> <%= pb_rails("body", props: { text: "Expanded Custom Layout", padding_bottom: "sm" }) %> <%= pb_rails("flex", props: { justify: "between" }) do %> <%= pb_rails("image", props: { size: "sm", url: "https://unsplash.it/500/400/?image=634" }) %> <%= pb_rails("image", props: { size: "sm", url: "https://unsplash.it/500/400/?image=634" }) %> <%= pb_rails("image", props: { size: "sm", url: "https://unsplash.it/500/400/?image=634" }) %> <%= pb_rails("image", props: { size: "sm", url: "https://unsplash.it/500/400/?image=634" }) %> <% end %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <%= pb_rails("table/table_header", props: { text: ""}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, id: "2" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right"}) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| |||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
The collapsible_content can display any content, including nested Table Rows.
Additionally, the collapsible_side_highlight can also be removed by setting it to false if needed. This prop is set to true by default.
NOTE: We advise against using the disable_hover Table prop when nesting Table Rows within a Table.
<% content = capture do %> <%= pb_rails("table", props: { container: false, border_radius: "none", size: "sm"}) do %> <%= pb_rails("background", props: { tag: "tr" }) do %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <% end %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <%= pb_rails("table/table_header", props: { text: ""}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: false, id: "3" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right"}) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | ||||||||||||
| ||||||||||||||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | ||||||||||||
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
The collapsible_content can also be used to display nested Tables within each Row.
NOTE: We advise against using the disable_hover Table prop when nesting Tables within a Table.
<% content = capture do %> <%= pb_rails("table", props: { container: false, border_radius: "none", size: "sm"}) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("background", props: { tag: "tr" }) do %> <%= pb_rails("table/table_header") do %>Alt Header<% end %> <%= pb_rails("table/table_header") do %>Alt Header<% end %> <%= pb_rails("table/table_header") do %>Alt Header<% end %> <%= pb_rails("table/table_header") do %>Alt Header<% end %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %> <%= pb_rails("pill", props: { text: "Pill", variant: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %> <%= pb_rails("pill", props: { text: "Pill", variant: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %>Expanded<% end %> <%= pb_rails("table/table_cell") do %> <%= pb_rails("pill", props: { text: "Pill", variant: "primary" }) %> <% end %> <% end %> <% end %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <%= pb_rails("table/table_header", props: { text: ""}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { collapsible: true, collapsible_content: content, collapsible_side_highlight: false, id: "4" }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text_align: "right"}) do %> <%= pb_rails("icon", props: { icon: "chevron-down", fixed_width: true, color: "primary" }) %> <% end %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <%= pb_rails("table/table_cell", props: { text: ""}) %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 | |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Clickable table rows do not require any additional props. This doc example showcases how to set them up using html_options/htmlOptions and click events. Using the global prop for cursor to set it to "pointer" is also recommended for better UX.
<%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Column 1" }) %> <%= pb_rails("table/table_header", props: { text: "Column 2" }) %> <%= pb_rails("table/table_header", props: { text: "Column 3" }) %> <%= pb_rails("table/table_header", props: { text: "Column 4" }) %> <%= pb_rails("table/table_header", props: { text: "Column 5" }) %> <%= pb_rails("table/table_header", props: { text: "" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row", props: { cursor: "pointer", html_options: { onclick: "alert('Row 1 clicked')" } }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 2" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5" }) %> <%= pb_rails("table/table_cell", props: { text_align: "right" }) do %> <%= pb_rails("icon", props: { color: "primary_action", fixed_width: true, icon: "chevron-right", size: "xs" }) %> <% end %> <% end %> <%= pb_rails("table/table_row", props: { cursor: "pointer", html_options: { onclick: "alert('Row 2 clicked')" } }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 2" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5" }) %> <%= pb_rails("table/table_cell", props: { text_align: "right" }) do %> <%= pb_rails("icon", props: { color: "primary_action", fixed_width: true, icon: "chevron-right", size: "xs" }) %> <% end %> <% end %> <%= pb_rails("table/table_row", props: { cursor: "pointer", html_options: { onclick: "alert('Row 3 clicked')" } }) do %> <%= pb_rails("table/table_cell", props: { text: "Value 1" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 2" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5" }) %> <%= pb_rails("table/table_cell", props: { text_align: "right" }) do %> <%= pb_rails("icon", props: { color: "primary_action", fixed_width: true, icon: "chevron-right", size: "xs" }) %> <% end %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | |
|---|---|---|---|---|---|
|
| Value 2 | Value 3 | Value 4 | Value 5 | |
|
| Value 2 | Value 3 | Value 4 | Value 5 | |
|
| Value 2 | Value 3 | Value 4 | Value 5 |
Use the Checkbox kit with the Table to achieve the selectable row functionality seen here.
<% checkboxes = [ { name: 'Coffee', id: 'coffee', checked: false }, { name: 'Ice Cream', id: 'ice-cream', checked: false }, { name: 'Chocolate', id: 'chocolate', checked: true } ] %> <%= pb_rails("flex", props: { justify: "end", margin_bottom: "sm" }) do %> <%= pb_rails("flex", props: { justify: "end", margin_bottom: "sm" }) do %> <%= pb_rails("button", props: { text: "Delete", id: "delete-button" }) %> <% end %> <% end %> <%= pb_rails("table", props: { size: "sm" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header") do %> <%= pb_rails("checkbox", props: { checked: true, value: "checkbox-value", name: "main-checkbox-selectable", indeterminate_main: true, indeterminate_main_labels: ["", ""], id: "checkbox-selectable" }) %> <% end %> <%= pb_rails("table/table_header", props: { text: "Column 1" }) %> <%= pb_rails("table/table_header", props: { text: "Column 2" }) %> <%= pb_rails("table/table_header", props: { text: "Column 3" }) %> <%= pb_rails("table/table_header", props: { text: "Column 4" }) %> <%= pb_rails("table/table_header", props: { text: "Column 5" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <% checkboxes.each_with_index do |checkbox, index| %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell") do %> <%= pb_rails("checkbox", props: { checked: checkbox[:checked], id: "#{checkbox[:id]}-selectable-checkbox", name: "#{checkbox[:id]}-selectable-checkbox", on_change: "updateCheckboxes(#{index})", value: "check-box value", indeterminate_parent: "checkbox-selectable" }) %> <% end %> <%= pb_rails("table/table_cell") do %> <%= pb_rails("image", props: { alt: "picture of a misty forest", size: "xs", url: "https://unsplash.it/500/400/?image=634" }) %> <% end %> <%= pb_rails("table/table_cell", props: { text: "Value 2" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 3" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 4" }) %> <%= pb_rails("table/table_cell", props: { text: "Value 5" }) %> <% end %> <% end %> <% end %> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Customize your header by removing the header borders with the header_style: "borderless" prop.
<%= pb_rails("table", props: { size: "sm", header_style: "borderless" }) do %> <thead> <tr> <th>Column 1</th> <th>Column 2</th> <th>Column 3</th> <th>Column 4</th> <th>Column 5</th> </tr> </thead> <tbody> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> <tr> <td>Value 1</td> <td>Value 2</td> <td>Value 3</td> <td>Value 4</td> <td>Value 5</td> </tr> </tbody> <% end %>
| Column 1 | Column 2 | Column 3 | Column 4 | Column 5 |
|---|---|---|---|---|
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
| Value 1 | Value 2 | Value 3 | Value 4 | Value 5 |
Further customize your header by using the table with background kit logic to give your table header a custom background color. Use the header_style: "floating" prop to visually nest the borderless table within a card or collapsible with a matching background color (the background_color passed to Background kit should match the background or background_color for the element in which it is nested).
<%= pb_rails("card", props: { background: "light" }) do %> <%= pb_rails("table", props: { size: "sm", header_style: "floating" }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("background", props: { background_color: "light", tag: "tr" }) do %> <%= pb_rails("table/table_header", props: { text: "Column 1"}) %> <%= pb_rails("table/table_header", props: { text: "Column 2"}) %> <%= pb_rails("table/table_header", props: { text: "Column 3"}) %> <%= pb_rails("table/table_header", props: { text: "Column 4"}) %> <%= pb_rails("table/table_header", props: { text: "Column 5"}) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { text: "Value 1"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 2"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 3"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 4"}) %> <%= pb_rails("table/table_cell", props: { text: "Value 5"}) %> <% end %> <% end %> <% end %> <% end %>
| Territory ID | Name | Title | Department | Branch | Start Date |
|---|---|---|---|---|---|
| 1 | Jennifer | Associate Scrum Master | Business Technology | Philadelphia |
Dec 31, 2024
|
| 2 | Nick | UX Engineer II | Business Technology | Philadelphia |
Jan 1, 2025
|
| 3 | Nida | Senior UX Engineer | Business Technology | Philadelphia |
Jan 2, 2025
|
| 4 | Justin | Director of User Experience Engineering | Business Technology | Philadelphia |
Jan 3, 2025
|
| 5 | Edward | UX Designer II | Business Technology | Philadelphia |
Jan 4, 2025
|
| 6 | Elisa | UX Engineer | Business Technology | Philadelphia |
Jan 5, 2025
|
| 7 | Gary | UX Engineer | Business Technology | Philadelphia |
Jan 6, 2025
|
| 8 | Barkley | Nitro Quality Ninja | Business Technology | Philadelphia |
Jan 7, 2025
|
| 9 | Aaron | Associate Nitro Quality Ninja | Business Technology | Philadelphia |
Jan 8, 2025
|
Set the variant prop to with_filter to render a Table with a filter. The variant automatically handles:
title prop to render title above the cardvariant: "with_filter": Enables the filter variantfilter_content: The filter's body content (inputs, buttons, etc.) built with pb_rails string concatenationfilter_props: A hash containing Filter-specific props like results, sort_menu, etc.title: Displays a title above the cardsize, collapse, etc.) can be used, but defaults are already set to match Design guidelinesThe Table kit automatically sets these Filter defaults (which you can override via filter_props):
background: falsemax_height: "50vh"min_width: "xs"popover_props: { width: "350px" }Alternatively, you can pass pre-rendered filter markup via the filter prop (e.g. for manual submission or custom filter helpers)—scroll down for that approach.
IMPORTANT NOTE:
The purpose of this variant is to provide an easy way to set up a Table with a Filter with Design standards applied by default.
If you are looking for more customization than this embedded variant provides, you may be better served by using the individual kits as demonstrated in our Table Filter Card Building Block as seen here.
<% users = [ { id: 1, name: "Jennifer", title: "Associate Scrum Master", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 1) }, { id: 2, name: "Nick", title: "UX Engineer II", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 2) }, { id: 3, name: "Nida", title: "Senior UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 3) }, { id: 4, name: "Justin", title: "Director of User Experience Engineering", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 4) }, { id: 5, name: "Edward", title: "UX Designer II", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 5) }, { id: 6, name: "Elisa", title: "UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 6) }, { id: 7, name: "Gary", title: "UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 7) }, { id: 8, name: "Barkley", title: "Nitro Quality Ninja", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 8) }, { id: 9, name: "Aaron", title: "Associate Nitro Quality Ninja", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 9) }, ] %> <% filter_content = pb_rails("text_input", props: { label: "Territory ID", placeholder: "Enter Territory ID" }) + pb_rails("typeahead", props: { label: "Title", options: [ { label: "Senior UX Engineer", value: "senior-ux-engineer" }, { label: "UX Engineer", value: "ux-engineer" }, { label: "UX Designer", value: "ux-designer" } ] }) + pb_rails("select", props: { blank_selection: "All Departments", label: "Department", options: [ { value: "Business Technology", text: "Business Technology" }, { value: "Customer Development", text: "Customer Development" }, { value: "Talent Acquisition", text: "Talent Acquisition" } ] }) + pb_rails("dropdown", props: { label: "Branch", options: [ { label: "Philadelphia", value: "philadelphia" }, { label: "New York", value: "new-york" }, { label: "Austin", value: "austin" } ] }) + pb_rails("date_picker", props: { label: "Start Date", padding_y: "sm", picker_id: "startedOn" }) + pb_rails("flex", props: { spacing: "between" }) do pb_rails("button", props: { text: "Filter", }) + pb_rails("button", props: { text: "Defaults", variant: "secondary" }) end %> <%= pb_rails("table", props: { variant: "with_filter", title: "Table Title Here", filter_content: filter_content, filter_props: { id: "user-table-filters-1", results: 9, sort_menu: [ { item: "Start Date", link: "?q[sorts]=started_on+asc", active: true, direction: "asc" }, { item: "First Name", link: "?q[sorts]=name+asc", active: false }, { item: "Title", link: "?q[sorts]=title+asc", active: false }, { item: "Department", link: "?q[sorts]=department+asc", active: false }, { item: "Branch", link: "?q[sorts]=branch+asc", active: false }, { item: "Territory ID", link: "?q[sorts]=territory_id+asc", active: false }, ], } }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Territory ID" }) %> <%= pb_rails("table/table_header", props: { text: "Name" }) %> <%= pb_rails("table/table_header", props: { text: "Title" }) %> <%= pb_rails("table/table_header", props: { text: "Department" }) %> <%= pb_rails("table/table_header", props: { text: "Branch" }) %> <%= pb_rails("table/table_header", props: { text: "Start Date", text_align: "right" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <% users.each do |user| %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" }, number_spacing: "tabular" }) { user[:id].to_s } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:name] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:title] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:department] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:branch] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) do %> <%= pb_rails("date", props: {alignment: "right", date: user[:start_date].to_s, show_current_year: true } ) %> <% end %> <% end %> <% end %> <% end %> <% end %>
Use the "with_filter" variant with an external filter (Option B): pass pre-rendered filter markup via the filter prop. Same layout as Variant with Filter (card, title, separator, flex); only the filter slot is supplied by you. Use this when you need:
variant: "with_filter"filter – Pre-rendered filter HTML (e.g. from capture { ... })When filter is present, filter_content and filter_props are ignored.
pb_rails("filter", ...) or any helper that returns filter markup).capture do ... end.filter prop.Example (generic pattern):
<% filter_output = capture do %>
<%= pb_rails("filter", props: { template: "single", results: 10, background: false }) do %>
<%= pb_rails("text_input", props: { label: "Name", placeholder: "Search by name" }) %>
<%= pb_rails("button", props: { text: "Apply" }) %>
<% end %>
<% end %>
<%= pb_rails("table", props: {
variant: "with_filter",
title: "My Table",
filter: filter_output,
}) do %>
<%# table_head / table_body ... %>
<% end %>
For Nitro apps that use a shared search/filter pattern, reference the example on Alpha for implementation details.
<%# External filter: capture any filter markup and pass it via the filter prop. Use your own helper (e.g. a search/filter form) or pb_rails("filter") as shown here. %> <% users = [ { name: "Alex", role: "Engineer" }, { name: "Sam", role: "Designer" }, { name: "Jordan", role: "Manager" }, ] %> <% filter_output = capture do %> <%= pb_rails("filter", props: { id: "external-filter-demo", template: "single", results: 3, background: false, sort_menu: [ { item: "Name", link: "#", active: true, direction: "asc" }, { item: "Role", link: "#", active: false }, ], }) do %> <%= pb_rails("text_input", props: { label: "Name", placeholder: "Search by name" }) %> <%= pb_rails("text_input", props: { label: "Role", placeholder: "e.g. Engineer, Designer" }) %> <%= pb_rails("button", props: { text: "Apply" }) %> <% end %> <% end %> <%= pb_rails("table", props: { variant: "with_filter", title: "Table with External Filter", filter: filter_output, }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Name" }) %> <%= pb_rails("table/table_header", props: { text: "Role" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <% users.each do |user| %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell") { user[:name] } %> <%= pb_rails("table/table_cell") { user[:role] } %> <% end %> <% end %> <% end %> <% end %>
| Territory ID | Name | Title | Department | Branch | Start Date |
|---|---|---|---|---|---|
| 1 | Jennifer | Associate Scrum Master | Business Technology | Philadelphia |
Dec 31, 2024
|
| 2 | Nick | UX Engineer II | Business Technology | Philadelphia |
Jan 1, 2025
|
| 3 | Nida | Senior UX Engineer | Business Technology | Philadelphia |
Jan 2, 2025
|
| 4 | Justin | Director of User Experience Engineering | Business Technology | Philadelphia |
Jan 3, 2025
|
| 5 | Edward | UX Designer II | Business Technology | Philadelphia |
Jan 4, 2025
|
| 6 | Elisa | UX Engineer | Business Technology | Philadelphia |
Jan 5, 2025
|
| 7 | Gary | UX Engineer | Business Technology | Philadelphia |
Jan 6, 2025
|
| 8 | Barkley | Nitro Quality Ninja | Business Technology | Philadelphia |
Jan 7, 2025
|
| 9 | Aaron | Associate Nitro Quality Ninja | Business Technology | Philadelphia |
Jan 8, 2025
|
| 10 | Sarah | Senior Product Manager | Business Technology | New York |
Jan 9, 2025
|
| 11 | Michael | Software Engineer III | Business Technology | Austin |
Jan 10, 2025
|
| 12 | Emma | Data Analyst II | Customer Development | Philadelphia |
Jan 11, 2025
|
| 13 | David | QA Engineer | Business Technology | New York |
Jan 12, 2025
|
| 14 | Lisa | UX Researcher | Business Technology | Philadelphia |
Jan 13, 2025
|
| 15 | James | DevOps Engineer | Business Technology | Austin |
Jan 14, 2025
|
| 16 | Anna | Product Designer | Business Technology | Philadelphia |
Jan 15, 2025
|
| 17 | Robert | Backend Engineer | Business Technology | New York |
Jan 16, 2025
|
| 18 | Maria | Frontend Developer | Business Technology | Austin |
Jan 17, 2025
|
| 19 | William | Tech Lead | Business Technology | Philadelphia |
Jan 18, 2025
|
| 20 | Jessica | Scrum Master | Business Technology | New York |
Jan 19, 2025
|
| 21 | Daniel | Software Architect | Business Technology | Austin |
Jan 20, 2025
|
| 22 | Laura | Business Analyst | Customer Development | Philadelphia |
Jan 21, 2025
|
| 23 | Chris | Security Engineer | Business Technology | New York |
Jan 22, 2025
|
| 24 | Ashley | UX Engineer III | Business Technology | Austin |
Jan 23, 2025
|
| 25 | Kevin | Platform Engineer | Business Technology | Philadelphia |
Jan 24, 2025
|
| 26 | Michelle | Content Designer | Business Technology | New York |
Jan 25, 2025
|
The with_filter variant can also be used with the Pagination kit as shown here. Simply set up your Pagination as normal, and pass the Pagination kit to the prop pagination as shown.
IMPORTANT NOTE: This is NOT a working example of pagination, please set up your use case with the relevant data in your controller. For more information on the Pagination Kit and how to use it, see the documentation here
<% users = [ { id: 1, name: "Jennifer", title: "Associate Scrum Master", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 1) }, { id: 2, name: "Nick", title: "UX Engineer II", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 2) }, { id: 3, name: "Nida", title: "Senior UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 3) }, { id: 4, name: "Justin", title: "Director of User Experience Engineering", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 4) }, { id: 5, name: "Edward", title: "UX Designer II", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 5) }, { id: 6, name: "Elisa", title: "UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 6) }, { id: 7, name: "Gary", title: "UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 7) }, { id: 8, name: "Barkley", title: "Nitro Quality Ninja", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 8) }, { id: 9, name: "Aaron", title: "Associate Nitro Quality Ninja", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 9) }, { id: 10, name: "Sarah", title: "Senior Product Manager", department: "Business Technology", branch: "New York", start_date: Date.new(2025, 1, 10) }, { id: 11, name: "Michael", title: "Software Engineer III", department: "Business Technology", branch: "Austin", start_date: Date.new(2025, 1, 11) }, { id: 12, name: "Emma", title: "Data Analyst II", department: "Customer Development", branch: "Philadelphia", start_date: Date.new(2025, 1, 12) }, { id: 13, name: "David", title: "QA Engineer", department: "Business Technology", branch: "New York", start_date: Date.new(2025, 1, 13) }, { id: 14, name: "Lisa", title: "UX Researcher", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 14) }, { id: 15, name: "James", title: "DevOps Engineer", department: "Business Technology", branch: "Austin", start_date: Date.new(2025, 1, 15) }, { id: 16, name: "Anna", title: "Product Designer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 16) }, { id: 17, name: "Robert", title: "Backend Engineer", department: "Business Technology", branch: "New York", start_date: Date.new(2025, 1, 17) }, { id: 18, name: "Maria", title: "Frontend Developer", department: "Business Technology", branch: "Austin", start_date: Date.new(2025, 1, 18) }, { id: 19, name: "William", title: "Tech Lead", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 19) }, { id: 20, name: "Jessica", title: "Scrum Master", department: "Business Technology", branch: "New York", start_date: Date.new(2025, 1, 20) }, { id: 21, name: "Daniel", title: "Software Architect", department: "Business Technology", branch: "Austin", start_date: Date.new(2025, 1, 21) }, { id: 22, name: "Laura", title: "Business Analyst", department: "Customer Development", branch: "Philadelphia", start_date: Date.new(2025, 1, 22) }, { id: 23, name: "Chris", title: "Security Engineer", department: "Business Technology", branch: "New York", start_date: Date.new(2025, 1, 23) }, { id: 24, name: "Ashley", title: "UX Engineer III", department: "Business Technology", branch: "Austin", start_date: Date.new(2025, 1, 24) }, { id: 25, name: "Kevin", title: "Platform Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 25) }, { id: 26, name: "Michelle", title: "Content Designer", department: "Business Technology", branch: "New York", start_date: Date.new(2025, 1, 26) }, ] %> <% filter_content = pb_rails("text_input", props: { label: "Territory ID", placeholder: "Enter Territory ID" }) + pb_rails("typeahead", props: { label: "Title", options: [ { label: "Senior UX Engineer", value: "senior-ux-engineer" }, { label: "UX Engineer", value: "ux-engineer" }, { label: "UX Designer", value: "ux-designer" } ] }) + pb_rails("select", props: { blank_selection: "All Departments", label: "Department", options: [ { value: "Business Technology", text: "Business Technology" }, { value: "Customer Development", text: "Customer Development" }, { value: "Talent Acquisition", text: "Talent Acquisition" } ] }) + pb_rails("dropdown", props: { label: "Branch", options: [ { label: "Philadelphia", value: "philadelphia" }, { label: "New York", value: "new-york" }, { label: "Austin", value: "austin" } ] }) + pb_rails("date_picker", props: { label: "Start Date", padding_y: "sm", picker_id: "startedOn" }) + pb_rails("flex", props: { spacing: "between" }) do pb_rails("button", props: { text: "Filter", }) + pb_rails("button", props: { text: "Defaults", variant: "secondary" }) end %> <%# Replace "model" in pagination here with your specific data source %> <% pagination_element = pb_rails("pagination", props: { model: @users, view: self, padding_y:"xs", margin_left:"lg" }) %> <%= pb_rails("table", props: { variant: "with_filter", title: "Table Title Here", filter_content: filter_content, pagination: pagination_element, filter_props: { id: "user-table-filters-2", results: users.length, sort_menu: [ { item: "Start Date", link: "?q[sorts]=started_on+asc", active: true, direction: "asc" }, { item: "First Name", link: "?q[sorts]=name+asc", active: false }, { item: "Title", link: "?q[sorts]=title+asc", active: false }, { item: "Department", link: "?q[sorts]=department+asc", active: false }, { item: "Branch", link: "?q[sorts]=branch+asc", active: false }, { item: "Territory ID", link: "?q[sorts]=territory_id+asc", active: false }, ], } }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Territory ID" }) %> <%= pb_rails("table/table_header", props: { text: "Name" }) %> <%= pb_rails("table/table_header", props: { text: "Title" }) %> <%= pb_rails("table/table_header", props: { text: "Department" }) %> <%= pb_rails("table/table_header", props: { text: "Branch" }) %> <%= pb_rails("table/table_header", props: { text: "Start Date", text_align: "right" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <% users.each do |user| %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" }, number_spacing: "tabular" }) { user[:id].to_s } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:name] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:title] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:department] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:branch] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) do %> <%= pb_rails("date", props: {alignment: "right", date: user[:start_date].to_s, show_current_year: true } ) %> <% end %> <% end %> <% end %> <% end %> <% end %>
| Territory ID | Name | Title | Department | Branch | Start Date |
|---|---|---|---|---|---|
| 1 | Jennifer | Associate Scrum Master | Business Technology | Philadelphia |
Dec 31, 2024
|
| 2 | Nick | UX Engineer II | Business Technology | Philadelphia |
Jan 1, 2025
|
| 3 | Nida | Senior UX Engineer | Business Technology | Philadelphia |
Jan 2, 2025
|
| 4 | Justin | Director of User Experience Engineering | Business Technology | Philadelphia |
Jan 3, 2025
|
| 5 | Edward | UX Designer II | Business Technology | Philadelphia |
Jan 4, 2025
|
| 6 | Elisa | UX Engineer | Business Technology | Philadelphia |
Jan 5, 2025
|
| 7 | Gary | UX Engineer | Business Technology | Philadelphia |
Jan 6, 2025
|
| 8 | Barkley | Nitro Quality Ninja | Business Technology | Philadelphia |
Jan 7, 2025
|
| 9 | Aaron | Associate Nitro Quality Ninja | Business Technology | Philadelphia |
Jan 8, 2025
|
The with_filter variant also offers 2 additional optional props:
card_props: An object containing Card-specific props.
title_props: An object containing Title-specific props.
The Table kit automatically sets these Card defaults (which you can override via card_props):
padding:"none"The Table kit automatically sets these Title defaults (which you can override via title_props):
size:3paddingY:"md"<% users = [ { id: 1, name: "Jennifer", title: "Associate Scrum Master", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 1) }, { id: 2, name: "Nick", title: "UX Engineer II", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 2) }, { id: 3, name: "Nida", title: "Senior UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 3) }, { id: 4, name: "Justin", title: "Director of User Experience Engineering", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 4) }, { id: 5, name: "Edward", title: "UX Designer II", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 5) }, { id: 6, name: "Elisa", title: "UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 6) }, { id: 7, name: "Gary", title: "UX Engineer", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 7) }, { id: 8, name: "Barkley", title: "Nitro Quality Ninja", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 8) }, { id: 9, name: "Aaron", title: "Associate Nitro Quality Ninja", department: "Business Technology", branch: "Philadelphia", start_date: Date.new(2025, 1, 9) }, ] %> <% filter_content = pb_rails("text_input", props: { label: "Territory ID", placeholder: "Enter Territory ID" }) + pb_rails("typeahead", props: { label: "Title", options: [ { label: "Senior UX Engineer", value: "senior-ux-engineer" }, { label: "UX Engineer", value: "ux-engineer" }, { label: "UX Designer", value: "ux-designer" } ] }) + pb_rails("select", props: { blank_selection: "All Departments", label: "Department", options: [ { value: "Business Technology", text: "Business Technology" }, { value: "Customer Development", text: "Customer Development" }, { value: "Talent Acquisition", text: "Talent Acquisition" } ] }) + pb_rails("dropdown", props: { label: "Branch", options: [ { label: "Philadelphia", value: "philadelphia" }, { label: "New York", value: "new-york" }, { label: "Austin", value: "austin" } ] }) + pb_rails("date_picker", props: { label: "Start Date", padding_y: "sm", picker_id: "startedOn" }) + pb_rails("flex", props: { spacing: "between" }) do pb_rails("button", props: { text: "Filter", }) + pb_rails("button", props: { text: "Defaults", variant: "secondary" }) end %> <%= pb_rails("table", props: { card_props: { margin_x: { xs: "sm", sm: "sm", md: "xl", lg: "xl", xl: "xl", default: "xl", } }, variant: "with_filter", title: "Table Title Here", title_props: { padding_left:{ xs: "sm", sm: "sm", md: "xl", lg: "xl", xl: "xl", default: "xl", } }, filter_content: filter_content, filter_props: { id: "user-table-filters-1", results: 9, sort_menu: [ { item: "Start Date", link: "?q[sorts]=started_on+asc", active: true, direction: "asc" }, { item: "First Name", link: "?q[sorts]=name+asc", active: false }, { item: "Title", link: "?q[sorts]=title+asc", active: false }, { item: "Department", link: "?q[sorts]=department+asc", active: false }, { item: "Branch", link: "?q[sorts]=branch+asc", active: false }, { item: "Territory ID", link: "?q[sorts]=territory_id+asc", active: false }, ], } }) do %> <%= pb_rails("table/table_head") do %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_header", props: { text: "Territory ID" }) %> <%= pb_rails("table/table_header", props: { text: "Name" }) %> <%= pb_rails("table/table_header", props: { text: "Title" }) %> <%= pb_rails("table/table_header", props: { text: "Department" }) %> <%= pb_rails("table/table_header", props: { text: "Branch" }) %> <%= pb_rails("table/table_header", props: { text: "Start Date", text_align: "right" }) %> <% end %> <% end %> <%= pb_rails("table/table_body") do %> <% users.each do |user| %> <%= pb_rails("table/table_row") do %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" }, number_spacing: "tabular" }) { user[:id].to_s } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:name] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:title] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:department] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) { user[:branch] } %> <%= pb_rails("table/table_cell", props: { margin_x: { xs: "sm" } }) do %> <%= pb_rails("date", props: {alignment: "right", date: user[:start_date].to_s, show_current_year: true } ) %> <% end %> <% end %> <% end %> <% end %> <% end %>
<%= pb_rails("list", props: {ordered: false, dark: false, borderless: false}) do %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <% end %>
<%= pb_rails("list", props: {ordered: false, dark: false, borderless: false, size: "large"}) do %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <% end %>
<%= pb_rails("list", props: {ordered: true, dark: false, borderless: false}) do %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <% end %>
<%= pb_rails("list", props: {ordered: false, dark: false, borderless: true}) do %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <% end %>
<%= pb_rails("list", props: {ordered: false, dark: false, borderless: false, xpadding: true}) do %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <%= pb_rails("list/item") do %> List Item <% end %> <% end %>
<%= pb_rails("list", props: {ordered: false, dark: false, borderless: false,layout: "left"}) do %> <% 5.times do%> <%= pb_rails("list/item") do %> <%= pb_rails("title", props:{text: "Label", size:4})%> <%= pb_rails("currency", props: { label: "Caption",amount: "2,000.50",size: "sm",}) %> <% end %> <%end%> <% end %>
<%= pb_rails("list", props: {ordered: false, dark: false, borderless: false,layout: "right"}) do %> <% 5.times do%> <%= pb_rails("list/item") do %> <%= pb_rails("title", props:{text: "Label", size:4})%> <%= pb_rails("currency", props: { label: "Caption",amount: "2,000.50",size: "sm",}) %> <% end %> <%end%> <% end %>
To display the "No Filters Selected" text, the filters prop must be null. As a suggestion, check the values of each key in your filters object. If they are all falsy, return null.
<%= pb_rails("filter", props: { min_width: "360px", id: "filter-demo-1", margin_bottom: "xl", filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "San Francisco"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template: "default", results: 1, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %> <%= pb_rails("filter", props: { min_width: "360px", id: "filter-demo-2", sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template: "default", results: 0, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
To remove the background from a filter, add the prop background with a value of false.
<%= pb_rails("filter", props: { min_width: "360px", id: "3", margin_bottom: "xl", background: false, filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "Las Vegas"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], results: 3, template: "single" }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "<i class='far fa-spinner fa-spin mr-3'></i>Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %> <%= pb_rails("filter", props: { min_width: "360px", id: "4", background: false, filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "Las Vegas"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], results: 3, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
<%= pb_rails("filter", props: { min_width: "360px", id: "2", filters: [ { name: "name", value: "John Wick" } ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], results: 546, template: "single" }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
To display results, use templates single or default.
<%= pb_rails("filter", props: { min_width: "360px", id: "nosort", filters: [ { name: "name", value: "John Wick" } ], results: 546, template: "filter_only", }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
<%= pb_rails("filter", props: { min_width: "360px", id: "fo", filters: [ { name: "name", value: "John Wick" } ], template:"filter_only", }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
<%= pb_rails("filter", props: { id: "so", sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template:"sort_only", }) %>
Filter can leverage the max-width property. Learn more in our visual guidelines.
<%= pb_rails("filter", props: { min_width: "360px", id: "25", position: "top", filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "San Francisco"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template: "default", results: 1, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away, like really far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: {max_width: "sm", label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
<%= pb_rails("filter", props: { max_height: "360px", id: "filter_max_height_rails", position: "top", filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "San Francisco"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template: "default", results: 1, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away, like really far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: {max_width: "sm", label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
Click the filter button above to toggle the popover.
To change the filter's popover position, use the placement prop with one of the positions:
"top" | "right" | "bottom" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end"
<%= pb_rails("filter", props: { min_width: "360px", id: "pla", filters: [ { name: "name", value: "John Wick" } ], placement: "right", template:"filter_only", }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: { label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
This kit uses the Popover kit under the hood for the Filter Popover which comes with its own set of props. If you want to apply certain Popover props to that underlying kit, you can do so by using the optional popover_props prop. This prop must be an object that contains valid Popover props. For a full list of Popover props, see here.
<%= pb_rails("filter", props: { id: "filter_popover_props", position: "top", filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "San Francisco"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template: "default", results: 1, popover_props: { width: "250px" }, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away, like really far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: {max_width: "sm", label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
By default, the filter popover attaches to the <body>. To attach it elsewhere, like inside a Turbo Frame, pass the append_to prop through popover_props. Set it to "parent" to place the tooltip inside its parent element, or pass any CSS selector (#id or .class) to specify a custom container.
<%= pb_rails("filter", props: { id: "filter_within_trubo_frames", position: "top", filters: [ { name: "name", value: "John Wick" }, { name: "city", value: "San Francisco"} ], sort_menu: [ { item: "Popularity", link: "?q[sorts]=managers_popularity+asc", active: true, direction: "desc" }, { item: "Mananger's Title", link: "?q[sorts]=managers_title+asc", active: false }, { item: "Manager's Name", link: "?q[sorts]=managers_name+asc", active: false }, ], template: "default", results: 1, popover_props: { append_to: "parent" }, }) do %> <% example_collection = [ OpenStruct.new(name: "USA", value: 1), OpenStruct.new(name: "Canada", value: 2), OpenStruct.new(name: "Brazil", value: 3), OpenStruct.new(name: "Philippines", value: 4), OpenStruct.new(name: "A galaxy far far away, like really far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far far away...", value: 5) ] %> <%= pb_rails("form", props: { form_system_options: { scope: :example, method: :get } }) do |form| %> <%= form.text_field :example_text_field, props: { label: true } %> <%= form.collection_select :example_collection_select, example_collection, :value, :name, props: {max_width: "sm", label: true } %> <%= form.actions do |action| %> <%= action.submit props: { text: "Apply", data: { disable_with: "pb_rails('icon', props: { icon: 'spinner', spin: true, fixed_width: true })Searching...".html_safe },}%> <%= action.button props: { type: "reset", text: "Clear", variant: "secondary" } %> <% end %> <% end %> <% end %>
You can customize the order of the colors you would like to use by using the colors prop. Only the data and status colors will work for Playbook charts. See the design page for reference.
By default legend kit uses data_1 color.
Pass the color prop and use any desired value from $data_colors, $status_colors, $product_colors and $category_colors list.
<%= pb_rails("legend", props: { color: "data_8", text: "Data 8" }) %> <%= pb_rails("legend", props: { color: "warning", text: "Warning" }) %> <%= pb_rails("legend", props: { color: "product_6_highlight", text: "Product 6 (highlight)" }) %> <%= pb_rails("legend", props: { color: "category_7", text: "Category 7" }) %>
The color prop also allows for use of custom colors passed in as HEX codes.
In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
Use custom CSS with classes or inline styles (as shown in these docs) to customize the appearance of prefix and suffix units.
<% data1 = [{ name: 'Data Used', y: 32 }] %> <% data2 = [{ name: 'Sales to Date', y: 65 }] %> <% chart_options_1 = { title: { text: "Data Usage", }, series: [{ data: data1 }], plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">GB</span>', }, }, }, } %> <% chart_options_2 = { title: { text: "Sales Goal", }, series: [{ data: data2 }], plotOptions: { solidgauge: { dataLabels: { format: '<span y="28" style="fill: #687887; font-size: 16px;">$</span>' + '<span class="fix" y="38">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">k</span>', }, }, }, } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_1 }) %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_2 }) %>
<% data = [{ name: "Capacity", y: 75 }] %> <% chart_options = { title: { text: "Seating Capacity", }, series: [{ data: data }], pane: { startAngle: 0, endAngle: 360, }, plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">%</span>', }, }, }, } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %>
By default, Highcharts set min to 0 and max to 100 but this can be customized if needed as shown here.
<% data = [{ name: "Rating", y: 4.5 }] %> <% chart_options = { title: { text: "Product Rating", }, yAxis: { min: 0, max: 5, lineWidth: 0, tickWidth: 0, minorTickInterval: nil, tickAmount: 2, tickPositions: [0, 5], labels: { y: 26, enabled: true, style: { color: '#C1CDD6', fontWeight:'700', } }, }, series: [{ data: data }], } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %>
The Gauge chart resizes dynamically to fit whatever element it's placed within.
Note: set overflow to hidden on the parent element when nesting gauges inside of flex items to best respond to shrinking screens.
<% chart_options = { series: [{ data:[{ name: "Point 1", y: 100 }] }] } %> <% chart_options_1 = { series: [{ data:[{ name: "Point 2", y: 75 }] }] } %> <% chart_options_2 = { series: [{ data:[{ name: "Point 3", y: 50 }] }] } %> <% chart_options_3 = { series: [{ data:[{ name: "Point 4", y: 25 }] }] } %> <%= pb_rails("flex", props: {wrap: true, align: "center"}) do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "400px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "300px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_1 }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "200px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_2 }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "155px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_3 }) %> <% end %> <% end %>
<% chart_options = { title: { text: "Fixed Height in Pixels", }, chart: { height: "400", }, series: [{ data: [{ name: "Pixels", y: 400 }] }], plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">px</span>', }, }, }, } %> <% chart_options_1 = { title: { text: "Height as Percentage of Width", }, chart: { height: "45%", }, series: [{ data: [{ name: "Percentage", y: 45 }] }], plotOptions: { solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">%</span>', }, }, }, } %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options_1 }) %>
Highcharts allows for any custom colors to be used. Custom data colors allow for color customization to match the needs of business requirements.
For React, pass the option plotOptions.solidgauge.borderColor with a Playbook token like colors. + data_1 | data_2 | data_3 | data_4 | data_5 | data_6 | data_7 | data_8. HEX colors are also available eg: #CA0095
For Rails, the option plotOptions.solidgauge.borderColor can only be used with HEX values as shown.
We are able to wrap the Highcharts Gauge kit within Playbook kits (such as Flex and Card components).
<% chart_options = { series:[{data:[{ name: "Name", y: 10 }]}], chart: { height: "150", }, plotOptions: { series: { animation: false, }, solidgauge: { dataLabels: { format: '<span class="fix">{y:,f}</span>' + '<span style="fill: #687887; font-size: 27px;">%</span>', }, }, }, } %> <%= pb_rails("flex", props: {wrap: true, padding: "xl", gap: "sm"}) do %> <%= pb_rails("flex/flex_item", props: {flex: 1, grow: true }) do %> <%= pb_rails("card", props: {max_width: "xs", padding: "md", }) do %> <%= pb_rails("title", props: {padding_bottom: "sm", size: 4, text: "Abandoned Calls" })%> <%= pb_rails("flex", props: {align: "stretch"}) do %> <%= pb_rails("flex", props: {margin_right: "sm", orientation: "column"}) do %> <%= pb_rails("body", props: {color: "light", padding_bottom: "sm",text: "Total Abandoned"}) %> <%= pb_rails("flex", props: {align: "baseline", padding_bottom: "sx"}) do %> <%= pb_rails("title", props: {size: 1, text: "39"})%> <%= pb_rails("title", props: {color: "light", size: 3, text: "calls"}) %> <% end %> <%= pb_rails("caption", props: {size: "xs", text: "of 390" }) %> <%end %> <%= pb_rails("section_separator", props: {align_self: "stretch", margin_right: "sm", orientation: "vertical" }) %> <%= pb_rails("flex", props: {orientation: "column", wrap: true}) do %> <%= pb_rails("body", props: {color: "light", text: "% Abandoned"}) %> <%= pb_rails("flex", props: {wrap: true}) do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "150px", overflow: "hidden", shrink: true}) do %> <%= pb_rails("pb_gauge_chart", props: { options: chart_options }) %> <% end %> <% end %> <% end %> <%end %> <% end %> <% end %> <% end %>
In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
<% chart_data = [{ name: 'Installation', data: [1475,200,3000,654,656] }, { name: 'Manufacturing', data: [4434,524,2320,440,500] }, { name: 'Sales & Distribution', data: [3387,743,1344,434,440,] }, { name: 'Project Development', data: [3227,878,999,780,1000] }, { name: 'Other', data: [1111,677,3245,500,200] }] %> <% chart_options = { series: chart_data, title: { text: 'Solar Employment Growth by Sector, 2010-2016', }, subtitle: { text: 'Source: thesolarfoundation.com', }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], }, yAxis: { title: { text: 'Number of Employees', }, }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <% chart_options = { series: chart_data, title: { text: 'Bar Graph with Legend', }, xAxis: { categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
Highcharts provides many options for customizing the legend display. This example showcases the following:
align can be used to align the legend left, right or center (defaults to center)
verticalAlign can be used to place the legend above the graph. Options are top, middle, bottom with default set to bottom
layout determines the position of the legend items. Options are horizontal, vertical or proximate with default set to horizontal layout: proximate will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x offsets the legend relative to its horizontal alignment. Negative x moves it to the left, positive x moves it to the right (defaults to 0)
y offsets the legend relative to its vertical alignment. Negative y moves it up, positive y moves it down (defaults to 0)
<% chart_data = [{ name: 'Installation', data: [1475] }, { name: 'Manufacturing', data: [4434] }, { name: 'Sales & Distribution', data: [3387] }, { name: 'Project Development', data: [3227] }, { name: 'Other', data: [1111] }] %> <% chart_options_right = { series: chart_data, title: { text: 'Alignment of Legend', }, xAxis: { categories: ['Jan'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true, align: 'right', verticalAlign: 'top', }, } %> <%= pb_rails("title", props: {size: 4, text: "align | verticalAlign", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_bar_graph", props: {options: chart_options_right}) %> <% chart_options_center = { series: chart_data, title: { text: 'Layout of Legend', }, xAxis: { categories: ['Jan'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true, align: 'center', verticalAlign: 'bottom', layout: 'vertical', }, } %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_bar_graph", props: {options: chart_options_center}) %> <% chart_options_left = { series: chart_data, title: { text: 'Offset of Legend', }, xAxis: { categories: ['Jan'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true, align: 'center', verticalAlign: 'bottom', layout: 'vertical', x: 100, y: 10, }, } %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_bar_graph", props: {options: chart_options_left}) %>
By default, Highcharts have a height of 400px, but this can be customized. You can override the default by specifying either a percentage or a fixed pixel value.
Using a percentage maintains a consistent aspect ratio across different responsive sizes. For example, setting the height to 50% makes the chart’s height half of its width.
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <% chart_options_pixel = { chart: { height: "300" }, series: chart_data, title: { text: "Fixed Height (300px)", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, } } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options_pixel}) %> <br /><br /> <% chart_options_percentage = { chart: { height: "50%" }, series: chart_data, title: { text: "Percentage Height (50%)", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, } } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options_percentage}) %>
A spline can be added by including a separate chart data with the type: 'spline' attribute.
A color can also be specified for the spline.
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }, { type: 'spline', name: 'Trend Line', data: [1975, 600, 2500, 924, 500], color: '#F9BB00', }] %> <% chart_options = { series: chart_data, title: { text: 'Bar Graph with Spline', }, subtitle: { text: 'Source: thesolarfoundation.com', }, xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May'], }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
Custom data colors allow for color customization to match the needs of business requirements. To accomplish this, you can use hex values.
<% chart_data = [{ name: 'Installation', data: [1475,200,3000,654,656] }, { name: 'Manufacturing', data: [4434,524,2320,440,500] }, { name: 'Sales & Distribution', data: [3387,743,1344,434,440,] }, { name: 'Project Development', data: [3227,878,999,780,1000] }, { name: 'Other', data: [1111,677,3245,500,200] }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Custom Data Colors", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, }, colors: ['#1CA05C', '#FD804C', '#144075', '#00C4D7', '#DA0014'], } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_data = [{ name: 'Installation', data: [1475, 200, 3000, 654, 656], }, { name: 'Manufacturing', data: [1270, 800, 200, 454, 956], }, { name: 'Sales & Distribution', data: [975, 1600, 1500, 924, 500], }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Stacked Columns", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, }, plotOptions: { column: { stacking: 'normal', borderWidth: 0, } }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_data = [{ name: 'Installation', data: [-475, 400, -1000, 354, -856], threshold: 0 }, { name: 'Manufacturing', data: [1475, 200, 1000, 654, -656], threshold: 0 }, { name: 'Sales & Distribution', data: [1270, 100, -1200, 554, 756], threshold: 0 }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Negative Numbers", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: { title: { text: "Number of Employees", }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }, { type: 'spline', name: 'Percentage', data: [48, 70, 25, 55, 72], color: '#F9BB00', yAxis: 1 }] %> <% chart_options = { series: chart_data, title: { text: "Bar Graph with Secondary Y-axis", }, xAxis: { categories: ["Jan", "Feb", "Mar", "Apr", "May"], }, yAxis: [{ format: "{value}%", labels: { style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, title: { text: "Number of Employees", style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, }, { labels: { style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, title: { text: "Percentage", style: { fontFamily: "Power Centra", color: "#C1CDD6", fontWeight: "bold", fontSize: "12px", }, }, opposite: true, min: 0, max: 100 }], legend: { enabled: true }, } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
<% chart_options = { chart: { type: 'bar' }, title: { text: 'Historic World Population by Region', align: 'left' }, subtitle: { text: 'Source: <a ' + 'href="https://en.wikipedia.org/wiki/List_of_continents_and_continental_subregions_by_population"' + 'target="_blank">Wikipedia.org</a>', align: 'left' }, xAxis: { categories: ['Africa', 'America', 'Asia', 'Europe'], lineWidth: 0 }, yAxis: { title: { text: '', }, }, tooltip: { valueSuffix: ' millions' }, plotOptions: { bar: { dataLabels: { enabled: true }, groupPadding: 0.1 } }, series: [{ name: 'Year 1990', data: [631, 727, 3202, 721] }, { name: 'Year 2000', data: [814, 841, 3714, 726] }, { name: 'Year 2018', data: [1276, 1007, 4561, 746] }], } %> <%= pb_rails("pb_bar_graph", props: {options: chart_options}) %>
In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
<% data = [ { name: "Waiting for Calls", y: 41, }, { name: "On Call", y: 49, }, { name: "After Call", y: 10, }, ] %> <% chart_options = { series: [{ data: data, innerSize: '100%', borderWidth: '20', }], } %> <div style="position: relative;"> <%= pb_rails("pb_circle_chart", props: { options: chart_options }) %> <div class="pb-circle-chart-block" style="position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; z-index: 1; text-align: center; pointer-events: none;"> <%= pb_rails("title", props: { size: 1, tag: "div", text: "83" }) %> </div> </div>
Custom data colors allow for color customization to match the needs of business requirements.
For React, import the colors from Playbook's tokens, then set custom colors in the plotOptions.pie.colors array using the desired color variables.
For Rails, only HEX colors can be used eg: #CA0095
<% data = [ { name: "Waiting for Calls", y: 41, }, { name: "On Call", y: 49, }, { name: "After Call", y: 10, }, ] %> <% chart_options = { series: [{ data: data }], plotOptions: { pie: { colors: ["#144075", "#1CA05C", "#F9BB00"], }, }, } %> <%= pb_rails("pb_circle_chart", props: { options: chart_options }) %>
<% data = [ { name: "Facebook", y: 2498, }, { name: "YouTube", y: 2000, }, { name: "WhatsApp", y: 2000, }, { name: "Facebook Messenger", y: 1300, }, { name: "WeChat", y: 1165, }, { name: "Instagram", y: 1000, }, { name: "Tik Tok", y: 800, },] %> <% chart_options = { series: [{ data: data }], plotOptions: { pie: { dataLabels: { enabled: true, }, }, }, } %> <%= pb_rails("pb_circle_chart", props: { options: chart_options }) %>
Layout options from Highcharts:
align Type: String | Values: left | center | right (defaults to center)
verticalAlign Type: String | Values: top | middle | bottom (defaults to bottom)
layout Type: String | Values: horizontal | vertical | proximate (defaults to horizontal)
x Type: Number (defaults to 0)
y Type: Number (defaults to 0)
layout determines the position of the legend items
layout: proximate will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x offsets the legend relative to its horizontal alignment. Negative x moves it to the left, positive x moves it to the right
y offsets the legend relative to its vertical alignment. Negative y moves it up, positive y moves it down.
<% data_first = [{ name: 'Bugs', y: 8, }, { name: 'Chores', y: 1, }, { name: 'Stories', y: 12, }] %> <% data_second = [{ name: 'Bugs', y: 8, }, { name: 'Chores', y: 1, }, { name: 'Stories', y: 12, }] %> <% data_third = [{ name: 'Queued', y: 7, }, { name: 'In Progress', y: 6, }, { name: 'Validation', y: 3, }, { name: 'Done', y: 6, }, ] %> <% chart_options_first = { title: { text: "Alignment of Legend" }, series: [{ data: data_first }], legend: { align: 'right', verticalAlign: 'top' }, plotOptions: { pie: { showInLegend: true } } } %> <% chart_options_second = { title: { text: "Layout of Legend" }, series: [{ data: data_second }], legend: { layout: 'vertical' }, plotOptions: { pie: { showInLegend: true } } } %> <% chart_options_third = { title: { text: "Offset of Legend" }, series: [{ data: data_third }], legend: { layout: 'vertical', x: 100, y: 10 }, plotOptions: { pie: { showInLegend: true } } } %> <%= pb_rails("title", props: { size: 4, text: "align | verticalAlign", padding_y:"sm" }) %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_first }) %> <%= pb_rails("title", props: { size: 4, text: "layout", padding_y:"sm" }) %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_second }) %> <%= pb_rails("title", props: { size: 4, text: "x | y", padding_y:"sm" }) %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_third }) %>
<% data = [ { name: 'Facebook', y: 2498, }, { name: 'YouTube', y: 2000, }, { name: 'WhatsApp', y: 2000, }, { name: 'Facebook Messenger', y: 1300, }, { name: 'WeChat', y: 1165, }, { name: 'Instagram', y: 1000, }, { name: 'Tik Tok', y: 800, }, ] %> <% chart_options = { series: [{ data: data }], title: { text: "Active Users on Social Media" }, } %> <%= pb_rails("pb_circle_chart", props: { options: chart_options }) %>
<% data_first = [ { name: 'Bugs', y: 8, }, { name: 'Chores', y: 1, }, { name: 'Stories', y: 12, }, ] %> <% data_second = [ { name: 'Queued', y: 7, }, { name: 'In Progress', y: 6, }, { name: 'Validation', y: 3, }, { name: 'Done', y: 6, }, ] %> <% data_third = [ { name: '1 Point Tickets', y: 2, }, { name: '3 Point Tickets', y: 5, }, { name: '5 Point Tickets', y: 6, }, { name: '8 Point Tickets', y: 3, }, { name: '13 Point Tickets', y: 1, }, ] %> <% data_fourth = [ { name: 'Facebook', y: 2498, }, { name: 'YouTube', y: 2000, }, { name: 'WhatsApp', y: 2000, }, { name: 'Facebook Messenger', y: 1300, }, { name: 'WeChat', y: 1165, }, { name: 'Instagram', y: 1000, }, { name: 'Tik Tok', y: 800, }, ] %> <% chart_options_small = { series: [{ data: data_first, innerSize: '35%' }], } %> <% chart_options_md = { series: [{ data: data_second, innerSize: '50%' }], } %> <% chart_options_lg = { series: [{ data: data_third, innerSize: '85%' }], } %> <% chart_options_xl = { series: [{ data: data_fourth, innerSize: '0%' }], } %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_small }) %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_md }) %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_lg }) %> <%= pb_rails("pb_circle_chart", props: { options: chart_options_xl }) %>
Tooltip options from Highcharts:
headerFormat Type: String | when set to null will disable the header.
pointFormat Type: String | defines the HTML template for each data point and supports custom HTML when useHTML is enabled.
useHTML Type: boolean (default false) | enables HTML rendering in tooltips.
{point.name} and {point.y} are useful values that can be referenced for each point in the graph.
<% data = [ { name: 'Waiting for Calls', y: 41, }, { name: 'On Call', y: 49, }, { name: 'After Call', y: 10, }, ] %> <% chart_options = { series: [{ data: data }], tooltip: { headerFormat: nil, pointFormat: '<p>Custom tooltip for {point.name} <br/>with value: {point.y}</p>', useHTML: true, }, } %> <%= pb_rails("pb_circle_chart", props: { options: chart_options }) %>
In order to use this kit, 'highcharts' and 'highcharts-react-official' must be installed in your repo.
<% data = [{ name: 'Installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175], }, { name: 'Manufacturing', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434], }, { name: 'Sales & Distribution', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387], }, { name: 'Project Development', data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227], }, { name: 'Other', data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111], }] %> <% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] %> <% chart_options = { series: data, title: { text: "Solar Employment Growth by Sector, 2010-2016" }, subtitle: { text: "Source: thesolarfoundation.com" }, xAxis: { categories: categories, }, yAxis: { title: { text: "Number of Employees", }, }, } %> <%= pb_rails("pb_line_graph", props: {options: chart_options}) %>
<% data = [{ name: 'Number of Installations', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175], }] %> <% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'] %> <% chart_options = { series: data, title: { text: "Line Graph with Legend" }, xAxis: { categories: categories, }, yAxis: { min: 0, title: { text: "Number of Employees", }, }, legend: { enabled: true, }, } %> <%= pb_rails("pb_line_graph", props: {options: chart_options}) %>
Highcharts provides many options for customizing the legend display. This example showcases the following:
align can be used to align the legend left, right or center (defaults to center)
verticalAlign can be used to place the legend above the graph. Options are top, middle, bottom with default set to bottom
layout determines the position of the legend items. Options are horizontal, vertical or proximate with default set to horizontal layout: proximate will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x offsets the legend relative to its horizontal alignment. Negative x moves it to the left, positive x moves it to the right (defaults to 0)
y offsets the legend relative to its vertical alignment. Negative y moves it up, positive y moves it down (defaults to 0)
<% data = [{ name: 'Installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175], }, { name: 'Manufacturing', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434], }, { name: 'Sales & Distribution', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387], }, { name: 'Project Development', data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227], }, { name: 'Other', data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111], }] %> <% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'] %> <% chartOptionsFirst = { title: { text: "Alignment of Legend" }, series: data, xAxis: { categories: categories, }, yAxis: { min: 0, title: { text: "Number of Employees", }, }, legend: { enabled: true, align: 'right', verticalAlign: 'top' }, } %> <%= pb_rails("title", props: {size: 4, text: "align | verticalAlign", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_line_graph", props: {options: chartOptionsFirst}) %> <% chartOptionsSecond = { title: { text: "Layout of Legend" }, series: data, xAxis: { categories: categories, }, yAxis: { min: 0, title: { text: "Number of Employees", }, }, legend: { enabled: true, layout: 'vertical' }, } %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_line_graph", props: {options: chartOptionsSecond}) %> <% chartOptionsThird = { title: { text: "Offset of Legend" }, series: data, xAxis: { categories: categories, }, yAxis: { min: 0, title: { text: "Number of Employees", }, }, legend: { enabled: true, layout: 'vertical', x: 100, y: 10 }, } %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("pb_line_graph", props: {options: chartOptionsThird}) %>
<% data = [{ name: 'Number of Installations', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175], }] %> <% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug'] %> <% chart_options = { series: data, title: { text: "Line Graph with Legend Non Clickable" }, xAxis: { categories: categories, }, yAxis: { title: { text: 'Number of Employees', }, }, legend: { enabled: true }, } %> <%= pb_rails("pb_line_graph", props: {options: chart_options, id: "installations-chart"}) %> <script> // Prevent legend item click events from toggling series visibility document.addEventListener('click', function (e) { var container = document.getElementById('installations-chart'); if (!container) return; var legend = container.querySelector('.highcharts-legend'); if (legend && legend.contains(e.target)) { e.stopImmediatePropagation(); e.preventDefault(); } }, true); </script>
By default, Highcharts have a height of 400px, but this can be customized. You can override the default by specifying either a percentage or a fixed pixel value.
Using a percentage maintains a consistent aspect ratio across different responsive sizes. For example, setting the height to 50% makes the chart’s height half of its width.
<% data = [{ name: 'Number of Installations', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175], }] %> <% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] %> <% chart_options_first = { title: { text: 'Fixed Height (300px)', }, chart: { height: '300px' }, xAxis: { categories: categories, }, yAxis: { min: 0, title: { text: 'Number of Employees', }, }, series: data } %> <% chart_options_second = { title: { text: 'Percentage Height (50%)', }, chart: { height: '50%' }, xAxis: { categories: categories, }, yAxis: { min: 0, title: { text: 'Number of Employees', }, }, series: data } %> <%= pb_rails("pb_line_graph", props: {options: chart_options_first}) %> <%= pb_rails("pb_line_graph", props: {options: chart_options_second}) %>
Custom data colors allow for color customization to match the needs of business requirements.
For React, import 'colors' from Playbook, then set custom colors in the colors array using the desired color variables. Hex colors are also available.
For Rails, HEX values are required.
<% data = [{ name: 'Installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175], }, { name: 'Manufacturing', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434], }, { name: 'Sales & Distribution', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387], }, { name: 'Project Development', data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227], }, { name: 'Other', data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111], }] %> <% categories = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] %> <% chart_options = { series: data, colors: ['#1CA05C', '#FD804C', '#144075', '#00C4D7', '#DA0014'], title: { text: "Line Graph with Custom Data Colors" }, xAxis: { categories: categories, }, yAxis: { title: { text: "Number of Employees", }, }, } %> <%= pb_rails("pb_line_graph", props: {options: chart_options}) %>