|
Year
|
New Enrollments
|
Scheduled Meetings
|
Attendance Rate
|
Completed Classes
|
Class Completion Rate
|
Graduated Students
|
|---|---|---|---|---|---|---|
|
2021
|
20
|
10
|
51%
|
3
|
33%
|
19
|
|
Quarter
|
|
|
|
|
|
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
Month
|
|
|
|
|
|
|
|
January
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
Day
|
|
|
|
|
|
|
|
10
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
20
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
February
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
Day
|
|
|
|
|
|
|
|
15
|
19
|
35
|
69%
|
8
|
75%
|
23
|
|
2022
|
25
|
17
|
75%
|
5
|
45%
|
32
|
|
Quarter
|
|
|
|
|
|
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
Month
|
|
|
|
|
|
|
|
January
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
Day
|
|
|
|
|
|
|
|
15
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
25
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
May
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
Day
|
|
|
|
|
|
|
|
2
|
19
|
35
|
69%
|
8
|
75%
|
23
|
|
2023
|
10
|
15
|
65%
|
4
|
49%
|
29
|
|
Quarter
|
|
|
|
|
|
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
Month
|
|
|
|
|
|
|
|
March
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
Day
|
|
|
|
|
|
|
|
10
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
11
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
April
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
Day
|
|
|
|
|
|
|
|
15
|
19
|
35
|
69%
|
8
|
75%
|
23
|
subrow_headers is an optional prop that if present will add header rows at each level of the nested data. The prop takes an array of strings, each string being the text for each header row. The array of strings must be in the order in which they need to be rendered in the UI according to depth.
enable_toggle_expansion is an additional optional prop that can be used in conjunction with the subRowHeaders prop. enable_toggle_expansion is a string that can be "all", "header" or "none". If set to "all", the toggle expansion button will appear in the table header as well as in the subRow headers. If set to "header", the button will only appear in header and NOT in subRow headers. This prop is set to "header" by default.
<% column_definitions = [ { accessor: "year", label: "Year", cellAccessors: ["quarter", "month", "day"], }, { accessor: "newEnrollments", label: "New Enrollments", }, { accessor: "scheduledMeetings", label: "Scheduled Meetings", }, { accessor: "attendanceRate", label: "Attendance Rate", }, { accessor: "completedClasses", label: "Completed Classes", }, { accessor: "classCompletionRate", label: "Class Completion Rate", }, { accessor: "graduatedStudents", label: "Graduated Students", } ] subrow_headers = ["Quarter", "Month", "Day"] %> <%= pb_rails("advanced_table", props: { id: "subrow-headers", table_data: @table_data, column_definitions: column_definitions, id: "test_table" }) do %> <%= pb_rails("advanced_table/table_header", props: { table_id: "subrow-headers", column_definitions: column_definitions }) %> <%= pb_rails("advanced_table/table_body", props: { table_id: "subrow-headers", table_data: @table_data, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all" }) %> <% end %>
|
Year
|
New Enrollments
|
Scheduled Meetings
|
Attendance Rate
|
Completed Classes
|
Class Completion Rate
|
Graduated Students
|
|---|---|---|---|---|---|---|
|
2022
|
25
|
17
|
75%
|
5
|
45%
|
32
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
January
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
15
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
25
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
May
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
2
|
19
|
35
|
69%
|
8
|
75%
|
23
|
|
2021
|
20
|
10
|
51%
|
3
|
33%
|
19
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
January
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
10
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
20
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
February
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
15
|
19
|
35
|
69%
|
8
|
75%
|
23
|
|
2023
|
10
|
15
|
65%
|
4
|
49%
|
29
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
March
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
10
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
11
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
April
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
15
|
19
|
35
|
69%
|
8
|
75%
|
23
|
Use the pinned_rows prop to pin specific rows to the top of an Advanced Table. Pinned rows will remain at the top when scrolling through table data and will not change position if sorting is used.
NOTE:
sticky: true via table_props (works with both responsive and non-responsive tables)table_data array must contain a unique id in order to attach an id to all Rows for this to function.pinned_rows takes a hash with a top key containing an array of row ids, as shown in the code snippet below.pinned_rows[:top]; all its children will automatically be pinned with it. If a child id is passed without the parent being pinned, nothing will be pinned.<%# 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 %> <% @table_data_with_id.sort! do |a, b| value_a = a[sort_param] || a[sort_param.to_sym] value_b = b[sort_param] || b[sort_param.to_sym] 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 %> <% column_definitions = [ { accessor: "year", label: "Year", cellAccessors: ["quarter", "month", "day"], sort_menu: [ { item: "Year", link: "?sort=year_asc#pinned_rows_table", active: params["sort"] == "year_asc", direction: "asc" }, { item: "Year", link: "?sort=year_desc#pinned_rows_table", active: params["sort"] == "year_desc", direction: "desc" } ], }, { accessor: "newEnrollments", label: "New Enrollments", }, { accessor: "scheduledMeetings", label: "Scheduled Meetings", }, { accessor: "attendanceRate", label: "Attendance Rate", }, { accessor: "completedClasses", label: "Completed Classes", }, { accessor: "classCompletionRate", label: "Class Completion Rate", }, { accessor: "graduatedStudents", label: "Graduated Students", } ] %> <% pinned_rows = { top: ["8"] } %> <%= pb_rails("advanced_table", props: { id: "pinned_rows_table", table_data: @table_data_with_id, column_definitions: column_definitions, max_height: "xs", pinned_rows: pinned_rows, responsive: "none", table_props: { sticky: true }}) do %> <%= pb_rails("advanced_table/table_header", props: { table_id: "pinned_rows_table", column_definitions: column_definitions }) %> <%= pb_rails("advanced_table/table_body", props: { table_id: "pinned_rows_table", table_data: @table_data_with_id, column_definitions: column_definitions, pinned_rows: pinned_rows }) %> <% end %>
|
|
New Enrollments
|
Scheduled Meetings
|
Attendance Rate
|
Completed Classes
|
Class Completion Rate
|
Graduated Students
|
|---|---|---|---|---|---|---|
|
2021
|
20
|
10
|
51%
|
3
|
33%
|
19
|
|
Quarter
|
|
|
|
|
|
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
Month
|
|
|
|
|
|
|
|
January
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
Day
|
|
|
|
|
|
|
|
10
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
20
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
February
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
Day
|
|
|
|
|
|
|
|
15
|
19
|
35
|
69%
|
8
|
75%
|
23
|
|
2022
|
25
|
17
|
75%
|
5
|
45%
|
32
|
|
Quarter
|
|
|
|
|
|
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
Month
|
|
|
|
|
|
|
|
January
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
Day
|
|
|
|
|
|
|
|
15
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
25
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
May
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
Day
|
|
|
|
|
|
|
|
2
|
19
|
35
|
69%
|
8
|
75%
|
23
|
|
2023
|
10
|
15
|
65%
|
4
|
49%
|
29
|
|
Quarter
|
|
|
|
|
|
|
|
Q1
|
2
|
35
|
32%
|
15
|
52%
|
36
|
|
Month
|
|
|
|
|
|
|
|
March
|
16
|
20
|
11%
|
13
|
47%
|
28
|
|
Day
|
|
|
|
|
|
|
|
10
|
34
|
28
|
97%
|
20
|
15%
|
17
|
|
11
|
43
|
23
|
66%
|
26
|
47%
|
9
|
|
April
|
20
|
41
|
95%
|
26
|
83%
|
43
|
|
Day
|
|
|
|
|
|
|
|
15
|
19
|
35
|
69%
|
8
|
75%
|
23
|
selectable_rows is a boolean prop that if present will add checkboxes to all rows that will allow for selecting rows.
When a parent row is clicked, it will check all nested children rows, Children rows can be manually checked or unchecked as well.
The data attribute data-selected-rows on the parent pb_advanced_table div will update dynamically with each selection to show an array of ids corresponding to the current selection.
NOTE: Each object within the table_data Array must contain a unique id in order to attach an id to all Rows for this to function.
<% column_definitions = [ { accessor: "year", label: "Year", cellAccessors: ["quarter", "month", "day"], }, { accessor: "newEnrollments", label: "New Enrollments", }, { accessor: "scheduledMeetings", label: "Scheduled Meetings", }, { accessor: "attendanceRate", label: "Attendance Rate", }, { accessor: "completedClasses", label: "Completed Classes", }, { accessor: "classCompletionRate", label: "Class Completion Rate", }, { accessor: "graduatedStudents", label: "Graduated Students", } ] subrow_headers = ["Quarter", "Month", "Day"] %> <%= pb_rails("advanced_table", props: { id: "selectable_rows", table_data: @table_data_with_id, column_definitions: column_definitions, selectable_rows: true }) do %> <%= pb_rails("advanced_table/table_header", props: { table_id: "selectable_rows", column_definitions: column_definitions, selectable_rows: true }) %> <%= pb_rails("advanced_table/table_body", props: { table_id: "selectable_rows", table_data: @table_data_with_id, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all", selectable_rows: true }) %> <% end %>
|
Year
|
New Enrollments
|
Scheduled Meetings
|
Attendance Rate
|
Completed Classes
|
Class Completion Rate
|
Graduated Students
|
|
|---|---|---|---|---|---|---|---|
|
2021
|
20
|
10
|
51%
|
3
|
33%
|
19
| |
|
2022
|
25
|
17
|
75%
|
5
|
45%
|
32
| |
|
2023
|
10
|
15
|
65%
|
4
|
49%
|
29
| |
|
2024
|
15
|
34
|
32%
|
6
|
67%
|
65
|
selectable_rows can also be used with tables without nested row data. Set enable_toggle_expansion: none to adjust the Advanced Table styling to fit a table without subrows.
The data attribute data-selected-rows on the parent pb_advanced_table div will update dynamically with each selection to show an array of ids corresponding to the current selection.
NOTE: Each object within the table_data Array must contain a unique id in order to attach an id to all Rows for this to function.
<% column_definitions = [ { accessor: "year", label: "Year", cellAccessors: ["quarter", "month", "day"], }, { accessor: "newEnrollments", label: "New Enrollments", }, { accessor: "scheduledMeetings", label: "Scheduled Meetings", }, { accessor: "attendanceRate", label: "Attendance Rate", }, { accessor: "completedClasses", label: "Completed Classes", }, { accessor: "classCompletionRate", label: "Class Completion Rate", }, { accessor: "graduatedStudents", label: "Graduated Students", } ] %> <%= pb_rails("advanced_table", props: { id: "selectable_rows_no_subrows", table_data: @table_data_no_subrows, column_definitions: column_definitions, selectable_rows: true, enable_toggle_expansion: "none", }) %>
|
Year
|
New Enrollments
|
Scheduled Meetings
|
Attendance Rate
|
Completed Classes
|
Class Completion Rate
|
Graduated Students
|
|
|---|---|---|---|---|---|---|---|
|
2021
|
20
|
10
|
51%
|
3
|
33%
|
19
| |
|
2022
|
25
|
17
|
75%
|
5
|
45%
|
32
| |
|
2023
|
10
|
15
|
65%
|
4
|
49%
|
29
| |
|
2024
|
15
|
34
|
32%
|
6
|
67%
|
65
|
Custom actions content can be rendered within the Actions Bar as shown in this doc example. The component passed to actions will be rendered on the right of the actionsBar.
You can utilize script tags with your actions to provide your buttons with any clickable events needed.
<% column_definitions = [ { accessor: "year", label: "Year", cellAccessors: ["quarter", "month", "day"], }, { accessor: "newEnrollments", label: "New Enrollments", }, { accessor: "scheduledMeetings", label: "Scheduled Meetings", }, { accessor: "attendanceRate", label: "Attendance Rate", }, { accessor: "completedClasses", label: "Completed Classes", }, { accessor: "classCompletionRate", label: "Class Completion Rate", }, { accessor: "graduatedStudents", label: "Graduated Students", } ] actions = [ pb_rails("circle_icon_button", props: { icon: "file-csv", variant: "link", id: "export-selected-rows-btn", data: { action_type: "export" } }), pb_rails("circle_icon_button", props: { icon: "trash-alt", variant: "link", id: "delete-selected-rows-btn", data: { action_type: "delete" } }) ] %> <%= pb_rails("advanced_table", props: { id: "selectable_rows_with_actions", table_data: @table_data_no_subrows, column_definitions: column_definitions, selectable_rows: true, enable_toggle_expansion: "none", actions: actions }) %> <script> // Handle action clicks using the data-selected-rows attribute window.handleActionClick = function(actionType) { const tableContainer = document.getElementById('selectable_rows_with_actions'); if (!tableContainer) return; // Get selected rows from the data attribute const selectedRowsJSON = tableContainer.getAttribute('data-selected-rows'); let selectedRowIds = []; try { // Parse the JSON string from the data attribute if (selectedRowsJSON) { selectedRowIds = JSON.parse(selectedRowsJSON); } } catch (e) { // Fallback if JSON parsing fails const checkboxes = tableContainer.querySelectorAll('input[type="checkbox"]:checked'); const selectedCheckboxes = Array.from(checkboxes).filter(checkbox => checkbox.id !== 'select-all-rows' && !checkbox.closest('#select-all-rows') ); selectedRowIds = selectedCheckboxes.map(checkbox => checkbox.id); } // Show appropriate message if (!selectedRowIds || selectedRowIds.length === 0) { alert('No Selection Made'); } else { const selectedRowsString = selectedRowIds.join(', '); if (actionType === 'export') { alert('Row ids ' + selectedRowsString + ' will be exported!'); } else if (actionType === 'delete') { alert('Row ids ' + selectedRowsString + ' will be deleted!'); } } }; // Add event listeners when the DOM is ready document.addEventListener('DOMContentLoaded', function() { // Get the buttons const exportBtn = document.getElementById('export-selected-rows-btn'); const deleteBtn = document.getElementById('delete-selected-rows-btn'); // Add click event listeners if (exportBtn) { exportBtn.addEventListener('click', function(e) { e.preventDefault(); window.handleActionClick('export'); }); } if (deleteBtn) { deleteBtn.addEventListener('click', function(e) { e.preventDefault(); window.handleActionClick('delete'); }); } // Optional: Event delegation through the action bar const actionBar = document.querySelector('.row-selection-actions-card'); if (actionBar) { actionBar.addEventListener('click', function(e) { const exportButton = e.target.closest('#export-selected-rows-btn'); const deleteButton = e.target.closest('#delete-selected-rows-btn'); if (exportButton) { e.preventDefault(); window.handleActionClick('export'); } else if (deleteButton) { e.preventDefault(); window.handleActionClick('delete'); } }); } }); </script>
|
Year
|
New Enrollments
|
Scheduled Meetings
|
Attendance Rate
|
Completed Classes
|
Class Completion Rate
|
Graduated Students
|
|
|---|---|---|---|---|---|---|---|
|
2021
|
20
|
10
|
51%
|
3
|
33%
|
19
| |
|
2022
|
25
|
17
|
75%
|
5
|
45%
|
32
| |
|
2023
|
10
|
15
|
65%
|
4
|
49%
|
29
| |
|
2024
|
15
|
34
|
32%
|
6
|
67%
|
65
|
show_actions_bar is an optional prop that renders the header at the top showing the row count. This is set to true by default but can be toggled off by setting it to false
<% column_definitions = [ { accessor: "year", label: "Year", cellAccessors: ["quarter", "month", "day"], }, { accessor: "newEnrollments", label: "New Enrollments", }, { accessor: "scheduledMeetings", label: "Scheduled Meetings", }, { accessor: "attendanceRate", label: "Attendance Rate", }, { accessor: "completedClasses", label: "Completed Classes", }, { accessor: "classCompletionRate", label: "Class Completion Rate", }, { accessor: "graduatedStudents", label: "Graduated Students", } ] %> <%= pb_rails("advanced_table", props: { id: "selectable_rows_with_header_no_action_bar", table_data: @table_data_no_subrows, column_definitions: column_definitions, selectable_rows: true, enable_toggle_expansion: "none", show_actions_bar: false }) %>
| Props | Type | Values |
|---|---|---|
gap |
array
|
none
xxs
xs
sm
md
lg
xl
|
max_width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
min_width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
width |
array
|
0%
xs
sm
md
lg
xl
xxl
0
none
100%
|
z_index |
array
|
1
2
3
4
5
6
7
8
9
10
max
|
number_spacing |
array
|
tabular
|
shadow |
array
|
none
deep
deeper
deepest
|
line_height |
array
|
tightest
tighter
tight
normal
loose
looser
loosest
|
display |
array
|
block
inline_block
inline
flex
inline_flex
none
grid
|
cursor |
array
|
auto
default
none
contextMenu
help
pointer
progress
wait
cell
crosshair
text
verticalText
alias
copy
move
noDrop
notAllowed
grab
grabbing
eResize
nResize
neResize
nwResize
sResize
seResize
swResize
wResize
ewResize
nsResize
neswResize
nwseResize
colResize
rowResize
allScroll
zoomIn
zoomOut
|
flex_direction |
array
|
row
column
rowReverse
columnReverse
|
flex_wrap |
array
|
wrap
nowrap
wrapReverse
|
justify_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
justify_self |
array
|
auto
start
end
center
stretch
|
align_items |
array
|
flexStart
flexEnd
start
end
center
baseline
stretch
|
align_content |
array
|
start
end
center
spaceBetween
spaceAround
spaceEvenly
|
align_self |
array
|
auto
start
end
center
stretch
baseline
|
flex |
array
|
auto
initial
0
1
2
3
4
5
6
7
8
9
10
11
12
none
|
flex_grow |
array
|
1
0
|
flex_shrink |
array
|
1
0
|
order |
array
|
1
2
3
4
5
6
7
8
9
10
11
12
|
position |
array
|
relative
absolute
fixed
sticky
|
hover |
array
|
|
border_radius |
array
|
none
xs
sm
md
lg
xl
rounded
|
text_align |
array
|
start
end
left
right
center
justify
justify-all
match-parent
|
overflow |
array
|
visible
hidden
scroll
auto
|
truncate |
array
|
1
2
3
4
5
|
left |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
top |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
right |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
bottom |
array
|
0
xxs
xs
sm
md
lg
xl
auto
initial
inherit
|
vertical_align |
array
|
baseline
super
top
middle
bottom
sub
text-top
text-bottom
|
height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
min_height |
array
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
overflow_x |
array
|
visible
hidden
scroll
auto
|
overflow_y |
array
|
visible
hidden
scroll
auto
|
classname |
string
|
|
dark |
boolean
|
|
column_gap |
string
|
|
row_gap |
string
|
|
margin |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
margin_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_bottom |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_left |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_right |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_top |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_x |
array
|
none
xxs
xs
sm
md
lg
xl
|
padding_y |
array
|
none
xxs
xs
sm
md
lg
xl
|
group_hover |
boolean
|
|
id |
string
|
|
data |
hashprop
|
|
aria |
hashprop
|
|
html_options |
hashprop
|
|
children |
proc
|
|
style |
hashprop
|
| Props | Type | Values | Default |
|---|---|---|---|
max_height |
enum
|
auto
xs
sm
md
lg
xl
xxl
xxxl
|
auto
|
table_data |
array
|
||
column_definitions |
array
|
||
column_group_border_color |
enum
|
text_lt_default
text_lt_light
text_lt_lighter
text_dk_default
text_dk_light
text_dk_lighter
none
|
none
|
enable_toggle_expansion |
enum
|
all
header
none
|
header
|
loading |
boolean
|
false
|
|
responsive |
enum
|
none
scroll
|
scroll
|
table_props |
hashprop
|
||
selectable_rows |
boolean
|
false
|
|
show_actions_bar |
boolean
|
true
|
|
actions |
array
|
||
scroll_bar_none |
boolean
|
false
|
|
row_styling |
array
|
||
inline_row_loading |
boolean
|
false
|
|
persist_toggle_expansion_button |
boolean
|
false
|
|
pinned_rows |
hashprop
|