playbook_ui 14.24.0.pre.rc.4 → 14.24.0.pre.rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/pb_kits/playbook/pb_advanced_table/Components/SortIconButton.tsx +24 -25
- data/app/pb_kits/playbook/pb_advanced_table/Components/TableHeaderCell.tsx +11 -11
- data/app/pb_kits/playbook/pb_advanced_table/Hooks/useTableState.ts +5 -2
- data/app/pb_kits/playbook/pb_advanced_table/SubKits/TableHeader.tsx +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.scss +25 -1
- data/app/pb_kits/playbook/pb_advanced_table/_advanced_table.tsx +4 -1
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.html.erb +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/advanced_table.test.jsx +34 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_header_rails.html.erb +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_rails.html.erb +1 -1
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_per_column.jsx +55 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_per_column.md +6 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_per_column_for_multi_column.jsx +80 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_per_column_for_multi_column.md +1 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/example.yml +2 -0
- data/app/pb_kits/playbook/pb_advanced_table/docs/index.js +3 -1
- data/app/pb_kits/playbook/pb_advanced_table/flat_advanced_table.js +4 -11
- data/app/pb_kits/playbook/pb_advanced_table/index.js +108 -125
- data/app/pb_kits/playbook/pb_advanced_table/table_body.rb +5 -4
- data/app/pb_kits/playbook/pb_advanced_table/table_header.rb +10 -4
- data/app/pb_kits/playbook/pb_advanced_table/table_row.rb +21 -4
- data/app/pb_kits/playbook/pb_checkbox/index.js +220 -30
- data/app/pb_kits/playbook/pb_multi_level_select/_helper_functions.tsx +18 -9
- data/app/pb_kits/playbook/pb_multi_level_select/_multi_level_select.tsx +3 -1
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_show_checked_children.html.erb +75 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_show_checked_children.jsx +94 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/_multi_level_select_show_checked_children.md +3 -0
- data/app/pb_kits/playbook/pb_multi_level_select/docs/index.js +1 -1
- data/app/pb_kits/playbook/pb_multi_level_select/multi_level_select.rb +3 -0
- data/dist/chunks/{_line_graph-BfCo79KE.js → _line_graph-D7DgMqnT.js} +1 -1
- data/dist/chunks/{_typeahead-Db4YQA5c.js → _typeahead-BzYZCpJO.js} +2 -2
- data/dist/chunks/{_weekday_stacked-9aguRqOv.js → _weekday_stacked-CCn-qLh_.js} +2 -2
- data/dist/chunks/{lib-DnQyMxO1.js → lib-CY5ZPzic.js} +2 -2
- data/dist/chunks/{pb_form_validation-kl-4Jv4t.js → pb_form_validation-D3b0JKHH.js} +1 -1
- data/dist/chunks/vendor.js +1 -1
- data/dist/menu.yml +1 -1
- data/dist/playbook-doc.js +1 -1
- data/dist/playbook-rails-react-bindings.js +1 -1
- data/dist/playbook-rails.js +1 -1
- data/dist/playbook.css +1 -1
- data/lib/playbook/version.rb +1 -1
- metadata +14 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2fc8bc4c28ba98e8b419b039faa4ba89ad98109b642e173d06bca803e72309c
|
4
|
+
data.tar.gz: cb961caa0145db83c0c4a7ab1362e87988f3a2dcc03a3378f621d7a1225d9d53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc3cb75f59e0c721cf4f8be86efe8032e5dfa5b7d3ac5d8a6604a14cd1caf95fd607d6c726d9c8595d5861001710bdb09e2ebb5cbbf946d545fd31d27f81846b
|
7
|
+
data.tar.gz: 7608b048945f5a4fd328e986e563f9d0914a3301ff84cefcd26d5db9c52b489f1d25b583b5dfa34584d46a7438f37e350401dd5a952032c9993a24fe2455b6e7
|
@@ -4,49 +4,48 @@ import { Header } from "@tanstack/react-table"
|
|
4
4
|
import { GenericObject } from "../../types"
|
5
5
|
|
6
6
|
import Icon from "../../pb_icon/_icon"
|
7
|
-
import { getAllIcons } from "../../utilities/icons/allicons"
|
8
7
|
|
9
8
|
import { displayIcon } from "../Utilities/IconHelpers"
|
10
9
|
|
11
10
|
type SortIconButtonProps = {
|
12
11
|
header: Header<GenericObject, unknown>
|
13
12
|
sortIcon?: string | string[]
|
13
|
+
enableSortingRemoval?: boolean
|
14
14
|
}
|
15
15
|
|
16
|
-
export const SortIconButton = ({ header, sortIcon }: SortIconButtonProps) => {
|
17
|
-
|
18
|
-
const
|
19
|
-
const secondIcon = displayIcon(sortIcon)[1]
|
20
|
-
const upIcon = getAllIcons()["arrowUpShortWide"].icon as unknown as { [key: string]: SVGElement }
|
21
|
-
const downIcon = getAllIcons()["arrowDownShortWide"].icon as unknown as { [key: string]: SVGElement }
|
16
|
+
export const SortIconButton = ({ header, sortIcon, enableSortingRemoval }: SortIconButtonProps) => {
|
17
|
+
const firstIcon = displayIcon(sortIcon)[0]
|
18
|
+
const secondIcon = displayIcon(sortIcon)[1]
|
22
19
|
|
23
20
|
return (
|
24
21
|
<>
|
25
|
-
{header.column.getIsSorted() === "desc"
|
26
|
-
<div
|
22
|
+
{header.column.getIsSorted() === "desc" && (
|
23
|
+
<div
|
24
|
+
className="sort-button-icon"
|
27
25
|
key={firstIcon}
|
26
|
+
style={{ paddingLeft: `${header?.index === 0 ? "2px" : "4px"}` }}
|
28
27
|
>
|
29
|
-
{ firstIcon === "arrow-up-short-wide" ? (
|
30
|
-
<Icon
|
31
|
-
className="svg-inline--fa"
|
32
|
-
customIcon={upIcon}
|
33
|
-
/> ) : (
|
34
28
|
<Icon icon={firstIcon} />
|
35
|
-
)}
|
36
29
|
</div>
|
37
|
-
)
|
38
|
-
|
30
|
+
)}
|
31
|
+
{header.column.getIsSorted() === "asc" && (
|
32
|
+
<div
|
33
|
+
className="sort-button-icon"
|
39
34
|
key={secondIcon}
|
35
|
+
style={{ paddingLeft: `${header?.index === 0 ? "2px" : "4px"}` }}
|
40
36
|
>
|
41
|
-
{ secondIcon === "arrow-down-short-wide" ? (
|
42
|
-
<Icon
|
43
|
-
className="svg-inline--fa"
|
44
|
-
customIcon={downIcon}
|
45
|
-
/> ) : (
|
46
37
|
<Icon icon={secondIcon} />
|
47
|
-
|
38
|
+
</div>
|
39
|
+
)}
|
40
|
+
{header.column.getIsSorted() === false && (
|
41
|
+
<div
|
42
|
+
className="sort-button-icon"
|
43
|
+
key={enableSortingRemoval ? "arrow-up-arrow-down" : secondIcon}
|
44
|
+
style={{ paddingLeft: `${header?.index === 0 ? "2px" : "4px"}` }}
|
45
|
+
>
|
46
|
+
<Icon icon={enableSortingRemoval ? "arrow-up-arrow-down" : secondIcon} />
|
48
47
|
</div>
|
49
48
|
)}
|
50
49
|
</>
|
51
|
-
)
|
52
|
-
}
|
50
|
+
);
|
51
|
+
};
|
@@ -50,6 +50,7 @@ export const TableHeaderCell = ({
|
|
50
50
|
expanded,
|
51
51
|
setExpanded,
|
52
52
|
expandByDepth,
|
53
|
+
enableSortingRemoval,
|
53
54
|
onExpandByDepthClick,
|
54
55
|
toggleExpansionIcon,
|
55
56
|
sortControl,
|
@@ -64,6 +65,7 @@ export const TableHeaderCell = ({
|
|
64
65
|
|
65
66
|
type justifyTypes = "none" | "center" | "start" | "end" | "between" | "around" | "evenly"
|
66
67
|
|
68
|
+
|
67
69
|
const toggleSortButton = (event: React.SyntheticEvent) => {
|
68
70
|
if (sortControl) {
|
69
71
|
const sortIsDesc = header?.column.getIsSorted() === "desc"
|
@@ -110,7 +112,8 @@ export const TableHeaderCell = ({
|
|
110
112
|
const visibleSiblings = parent.columns.filter(columnHasVisibleLeaf);
|
111
113
|
return visibleSiblings.at(-1) === header.column;
|
112
114
|
})();
|
113
|
-
|
115
|
+
|
116
|
+
|
114
117
|
const cellClassName = classnames(
|
115
118
|
"table-header-cells",
|
116
119
|
`${showActionsBar && isActionBarVisible && "header-cells-with-actions"}`,
|
@@ -256,12 +259,9 @@ const isToggleExpansionEnabled =
|
|
256
259
|
)}
|
257
260
|
|
258
261
|
<Flex
|
259
|
-
className={`${header?.index === 0 &&
|
260
|
-
|
261
|
-
|
262
|
-
cursor={header?.index === 0 && enableSorting ? "pointer" : "default"}
|
263
|
-
{...(header?.index === 0 &&
|
264
|
-
enableSorting && {
|
262
|
+
className={`${header?.index === 0 && enableSorting && "header-sort-button pb_th_link"} ${header?.index !== 0 && header?.column.getCanSort() && "header-sort-secondary-columns"}`}
|
263
|
+
cursor={((header?.index !== 0 && header?.column.getCanSort()) || (header?.index === 0 && enableSorting) ? "pointer" : "default")}
|
264
|
+
{...(((header?.index !== 0 && header?.column.getCanSort()) || (header?.index === 0 && enableSorting)) && {
|
265
265
|
htmlOptions: {
|
266
266
|
onClick: (event: React.MouseEvent) => toggleSortButton(event),
|
267
267
|
onKeyDown: (event: React.KeyboardEvent) => {
|
@@ -279,13 +279,13 @@ const isToggleExpansionEnabled =
|
|
279
279
|
{flexRender(header?.column.columnDef.header, header?.getContext())}
|
280
280
|
</div>
|
281
281
|
|
282
|
-
{header?.index === 0 &&
|
283
|
-
header.column.getCanSort() &&
|
284
|
-
enableSorting &&
|
282
|
+
{((header?.index !== 0 && header?.column.getCanSort()) || (header?.index === 0 && enableSorting)) &&
|
285
283
|
(loading ? (
|
286
284
|
<div className="loading-toggle-icon" />
|
287
285
|
) : (
|
288
|
-
<SortIconButton
|
286
|
+
<SortIconButton
|
287
|
+
enableSortingRemoval={enableSortingRemoval}
|
288
|
+
header={header}
|
289
289
|
sortIcon={sortIcon}
|
290
290
|
/>
|
291
291
|
))}
|
@@ -16,8 +16,10 @@ import { createCellFunction } from "../Utilities/CellRendererUtils";
|
|
16
16
|
interface UseTableStateProps {
|
17
17
|
tableData: GenericObject[];
|
18
18
|
columnDefinitions: GenericObject[];
|
19
|
+
enableSortingRemoval?: boolean;
|
19
20
|
expandedControl?: GenericObject;
|
20
21
|
sortControl?: GenericObject;
|
22
|
+
firstColumnSort?: boolean;
|
21
23
|
onRowToggleClick?: (arg: Row<GenericObject>) => void;
|
22
24
|
selectableRows?: boolean;
|
23
25
|
initialLoadingRowsCount?: number;
|
@@ -38,6 +40,7 @@ interface UseTableStateProps {
|
|
38
40
|
export function useTableState({
|
39
41
|
tableData,
|
40
42
|
columnDefinitions,
|
43
|
+
enableSortingRemoval,
|
41
44
|
expandedControl,
|
42
45
|
sortControl,
|
43
46
|
onRowToggleClick,
|
@@ -91,11 +94,11 @@ export function useTableState({
|
|
91
94
|
columns: buildColumns(column.columns, false),
|
92
95
|
};
|
93
96
|
}
|
94
|
-
|
95
97
|
// Define the base column structure
|
96
98
|
const columnStructure = {
|
97
99
|
...columnHelper.accessor(column.accessor, {
|
98
100
|
header: column.header ?? column.label ?? "",
|
101
|
+
enableSorting: isFirstColumn || column.enableSort === true,
|
99
102
|
}),
|
100
103
|
};
|
101
104
|
|
@@ -166,7 +169,7 @@ export function useTableState({
|
|
166
169
|
getCoreRowModel: getCoreRowModel(),
|
167
170
|
getExpandedRowModel: getExpandedRowModel(),
|
168
171
|
getSortedRowModel: getSortedRowModel(),
|
169
|
-
enableSortingRemoval:
|
172
|
+
enableSortingRemoval: enableSortingRemoval,
|
170
173
|
sortDescFirst: true,
|
171
174
|
onRowSelectionChange: setRowSelection,
|
172
175
|
onRowPinningChange,
|
@@ -422,6 +422,15 @@
|
|
422
422
|
padding: 2px;
|
423
423
|
}
|
424
424
|
|
425
|
+
.header-sort-secondary-columns {
|
426
|
+
color: $primary !important;
|
427
|
+
|
428
|
+
&:hover {
|
429
|
+
background-color: rgba($primary, 0.03);
|
430
|
+
border-radius: $border_radius_md;
|
431
|
+
}
|
432
|
+
}
|
433
|
+
|
425
434
|
.toggle-all-icon {
|
426
435
|
@extend .button-icon;
|
427
436
|
@extend %primary-color-pseudo;
|
@@ -967,4 +976,19 @@
|
|
967
976
|
// Outside of the pb_advanced_table class for popover
|
968
977
|
.pb-advanced-table-popover-option:hover {
|
969
978
|
background-color: $bg_light;
|
970
|
-
}
|
979
|
+
}
|
980
|
+
// Removes borders when Wrapped inside the Card Kit
|
981
|
+
[class^=pb_card_kit] > .pb_advanced_table .pb_advanced_table_body .last-cell,
|
982
|
+
[class^=pb_card_kit] > .pb_advanced_table .pb_advanced_table_header .last-header-cell,
|
983
|
+
[class^=pb_card_kit] > .pb_advanced_table .pb_advanced_table_body tr td:last-child,
|
984
|
+
[class^=pb_card_kit] > .pb_advanced_table .pb_advanced_table_header tr th:last-child {
|
985
|
+
border-right: none !important;
|
986
|
+
}
|
987
|
+
|
988
|
+
// Removes borders when Wrapped inside the Card Kit
|
989
|
+
[class^=pb_card_kit] > .pb_advanced_table tr:last-child,
|
990
|
+
[class^=pb_card_kit] > .pb_advanced_table .last-row-cell {
|
991
|
+
td {
|
992
|
+
border-bottom: none !important;
|
993
|
+
}
|
994
|
+
}
|
@@ -40,6 +40,7 @@ type AdvancedTableProps = {
|
|
40
40
|
dark?: boolean
|
41
41
|
data?: { [key: string]: string }
|
42
42
|
enableToggleExpansion?: "all" | "header" | "none"
|
43
|
+
enableSortingRemoval?: boolean
|
43
44
|
expandedControl?: GenericObject
|
44
45
|
expandByDepth?: { [key: string]: string | number }
|
45
46
|
onExpandByDepthClick?: (arg: number, arg1: any) => void
|
@@ -87,6 +88,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
87
88
|
dark = false,
|
88
89
|
data = {},
|
89
90
|
enableToggleExpansion = "header",
|
91
|
+
enableSortingRemoval = false,
|
90
92
|
expandedControl,
|
91
93
|
expandByDepth,
|
92
94
|
onExpandByDepthClick,
|
@@ -122,7 +124,6 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
122
124
|
// Component refs
|
123
125
|
const tableWrapperRef = useRef<HTMLDivElement>(null);
|
124
126
|
|
125
|
-
// Initialize table state
|
126
127
|
const {
|
127
128
|
table,
|
128
129
|
expanded,
|
@@ -137,6 +138,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
137
138
|
} = useTableState({
|
138
139
|
tableData,
|
139
140
|
columnDefinitions,
|
141
|
+
enableSortingRemoval,
|
140
142
|
expandedControl,
|
141
143
|
sortControl,
|
142
144
|
onRowToggleClick,
|
@@ -333,6 +335,7 @@ const AdvancedTable = (props: AdvancedTableProps) => {
|
|
333
335
|
columnGroupBorderColor={columnGroupBorderColor}
|
334
336
|
columnVisibilityControl={columnVisibilityControl}
|
335
337
|
customSort={customSort}
|
338
|
+
enableSortingRemoval={enableSortingRemoval}
|
336
339
|
enableToggleExpansion={enableToggleExpansion}
|
337
340
|
enableVirtualization={virtualizedRows}
|
338
341
|
expandByDepth={expandByDepth}
|
@@ -11,7 +11,7 @@
|
|
11
11
|
<% if content.present? %>
|
12
12
|
<% content.presence %>
|
13
13
|
<% else %>
|
14
|
-
<%= pb_rails("advanced_table/table_header", props: { column_definitions: object.column_definitions, enable_toggle_expansion: object.enable_toggle_expansion, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, show_actions_bar: object.show_actions_bar }) %>
|
14
|
+
<%= pb_rails("advanced_table/table_header", props: { id: object.id, column_definitions: object.column_definitions, enable_toggle_expansion: object.enable_toggle_expansion, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, show_actions_bar: object.show_actions_bar }) %>
|
15
15
|
<%= pb_rails("advanced_table/table_body", props: { id: object.id, table_data: object.table_data, column_definitions: object.column_definitions, responsive: object.responsive, loading: object.loading, selectable_rows: object.selectable_rows, enable_toggle_expansion: object.enable_toggle_expansion, row_styling: object.row_styling }) %>
|
16
16
|
<% end %>
|
17
17
|
<% end %>
|
@@ -124,6 +124,23 @@ const columnDefinitions = [
|
|
124
124
|
},
|
125
125
|
]
|
126
126
|
|
127
|
+
const columnDefinitionsSort = [
|
128
|
+
{
|
129
|
+
accessor: "year",
|
130
|
+
label: "Year",
|
131
|
+
cellAccessors: ["quarter", "month", "day"],
|
132
|
+
},
|
133
|
+
{
|
134
|
+
accessor: "newEnrollments",
|
135
|
+
label: "New Enrollments",
|
136
|
+
enableSort: true,
|
137
|
+
},
|
138
|
+
{
|
139
|
+
accessor: "scheduledMeetings",
|
140
|
+
label: "Scheduled Meetings",
|
141
|
+
},
|
142
|
+
];
|
143
|
+
|
127
144
|
const columnDefinitionsCustomRenderer = [
|
128
145
|
{
|
129
146
|
accessor: "year",
|
@@ -676,3 +693,20 @@ test("rowStyling prop works as expected", () => {
|
|
676
693
|
const row1 = tableBody.querySelector('tr:nth-child(1)')
|
677
694
|
expect(row1).toHaveStyle({backgroundColor: colors.white, color: colors.black})
|
678
695
|
})
|
696
|
+
|
697
|
+
test("Sort icon renders with enableSort on individual columns", () => {
|
698
|
+
render(
|
699
|
+
<AdvancedTable
|
700
|
+
columnDefinitions={columnDefinitionsSort}
|
701
|
+
data={{ testid: testId }}
|
702
|
+
tableData={MOCK_DATA}
|
703
|
+
/>
|
704
|
+
);
|
705
|
+
|
706
|
+
const kit = screen.getByTestId(testId);
|
707
|
+
const sortIcon = kit.querySelector(".sort-button-icon");
|
708
|
+
expect(sortIcon).toBeInTheDocument();
|
709
|
+
const sortButton = kit.querySelector(".header-sort-secondary-columns");
|
710
|
+
expect(sortButton).toBeInTheDocument();
|
711
|
+
});
|
712
|
+
|
data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_selectable_rows_rails.html.erb
CHANGED
@@ -34,6 +34,6 @@
|
|
34
34
|
%>
|
35
35
|
|
36
36
|
<%= pb_rails("advanced_table", props: { id: "selectable_rows", table_data: @table_data_with_id, column_definitions: column_definitions, selectable_rows: true }) do %>
|
37
|
-
<%= pb_rails("advanced_table/table_header", props: { column_definitions: column_definitions, selectable_rows: true }) %>
|
37
|
+
<%= pb_rails("advanced_table/table_header", props: { id: "selectable_rows", column_definitions: column_definitions, selectable_rows: true }) %>
|
38
38
|
<%= pb_rails("advanced_table/table_body", props: { id: "selectable_rows", table_data: @table_data_with_id, column_definitions: column_definitions, subrow_headers: subrow_headers, enable_toggle_expansion: "all", selectable_rows: true }) %>
|
39
39
|
<% end %>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import React from "react"
|
2
|
+
import AdvancedTable from '../../pb_advanced_table/_advanced_table'
|
3
|
+
import MOCK_DATA from "./advanced_table_mock_data.json"
|
4
|
+
|
5
|
+
const AdvancedTableSortPerColumn = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
accessor: "newEnrollments",
|
14
|
+
label: "New Enrollments",
|
15
|
+
enableSort: true,
|
16
|
+
},
|
17
|
+
{
|
18
|
+
accessor: "scheduledMeetings",
|
19
|
+
label: "Scheduled Meetings",
|
20
|
+
},
|
21
|
+
{
|
22
|
+
accessor: "attendanceRate",
|
23
|
+
label: "Attendance Rate",
|
24
|
+
enableSort: true,
|
25
|
+
},
|
26
|
+
{
|
27
|
+
accessor: "completedClasses",
|
28
|
+
label: "Completed Classes",
|
29
|
+
},
|
30
|
+
{
|
31
|
+
accessor: "classCompletionRate",
|
32
|
+
label: "Class Completion Rate",
|
33
|
+
},
|
34
|
+
{
|
35
|
+
accessor: "graduatedStudents",
|
36
|
+
label: "Graduated Students",
|
37
|
+
},
|
38
|
+
]
|
39
|
+
|
40
|
+
return (
|
41
|
+
<div>
|
42
|
+
<AdvancedTable
|
43
|
+
columnDefinitions={columnDefinitions}
|
44
|
+
enableSortingRemoval
|
45
|
+
tableData={MOCK_DATA}
|
46
|
+
{...props}
|
47
|
+
>
|
48
|
+
<AdvancedTable.Header />
|
49
|
+
<AdvancedTable.Body />
|
50
|
+
</AdvancedTable>
|
51
|
+
</div>
|
52
|
+
)
|
53
|
+
}
|
54
|
+
|
55
|
+
export default AdvancedTableSortPerColumn;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Sorting can now be enabled on any of the columns. To do this, add `enableSort:true` to the columnDefinition of the column you want sorting enabled on. Once enabled, clicking on the header will toggle sort between ascending and descending.
|
2
|
+
|
3
|
+
The optional `enableSortingRemoval` prop can also be used in conjunction with sorting functionality. This prop is set to 'false' by default but if set to 'true' sorting order will circle like: 'none' -> 'desc' -> 'asc' -> 'none' -> ...
|
4
|
+
It is recommended that `enableSortingRemoval` be set to 'true' when sort is enabled on mutiple columns so that sorting direction is always clear via the sort icon.
|
5
|
+
|
6
|
+
__NOTE:__ For sort on the first column, continue to use the separate `enableSorting` prop on AdvancedTable.Header as [shown here](https://playbook.powerapp.cloud/kits/advanced_table/sorting/react#enable-sorting).
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import React from "react"
|
2
|
+
import AdvancedTable from '../../pb_advanced_table/_advanced_table'
|
3
|
+
import MOCK_DATA from "./advanced_table_mock_data.json"
|
4
|
+
|
5
|
+
const AdvancedTableSortPerColumnForMultiColumn = (props) => {
|
6
|
+
const columnDefinitions = [
|
7
|
+
{
|
8
|
+
accessor: "year",
|
9
|
+
label: "Year",
|
10
|
+
cellAccessors: ["quarter", "month", "day"],
|
11
|
+
},
|
12
|
+
{
|
13
|
+
label: "Enrollment Data",
|
14
|
+
columns: [
|
15
|
+
{
|
16
|
+
label: "Enrollment Stats",
|
17
|
+
columns: [
|
18
|
+
{
|
19
|
+
accessor: "newEnrollments",
|
20
|
+
label: "New Enrollments",
|
21
|
+
enableSort: true,
|
22
|
+
},
|
23
|
+
{
|
24
|
+
accessor: "scheduledMeetings",
|
25
|
+
label: "Scheduled Meetings",
|
26
|
+
},
|
27
|
+
],
|
28
|
+
},
|
29
|
+
],
|
30
|
+
},
|
31
|
+
{
|
32
|
+
label: "Performance Data",
|
33
|
+
columns: [
|
34
|
+
{
|
35
|
+
label: "Completion Metrics",
|
36
|
+
columns: [
|
37
|
+
{
|
38
|
+
accessor: "completedClasses",
|
39
|
+
label: "Completed Classes",
|
40
|
+
enableSort: true,
|
41
|
+
},
|
42
|
+
{
|
43
|
+
accessor: "classCompletionRate",
|
44
|
+
label: "Class Completion Rate",
|
45
|
+
},
|
46
|
+
],
|
47
|
+
},
|
48
|
+
{
|
49
|
+
label: "Attendance",
|
50
|
+
columns: [
|
51
|
+
{
|
52
|
+
accessor: "attendanceRate",
|
53
|
+
label: "Attendance Rate",
|
54
|
+
},
|
55
|
+
{
|
56
|
+
accessor: "scheduledMeetings",
|
57
|
+
label: "Scheduled Meetings",
|
58
|
+
},
|
59
|
+
],
|
60
|
+
},
|
61
|
+
],
|
62
|
+
},
|
63
|
+
];
|
64
|
+
|
65
|
+
return (
|
66
|
+
<div>
|
67
|
+
<AdvancedTable
|
68
|
+
columnDefinitions={columnDefinitions}
|
69
|
+
enableSortingRemoval
|
70
|
+
tableData={MOCK_DATA}
|
71
|
+
{...props}
|
72
|
+
>
|
73
|
+
<AdvancedTable.Header enableSorting />
|
74
|
+
<AdvancedTable.Body />
|
75
|
+
</AdvancedTable>
|
76
|
+
</div>
|
77
|
+
)
|
78
|
+
}
|
79
|
+
|
80
|
+
export default AdvancedTableSortPerColumnForMultiColumn;
|
data/app/pb_kits/playbook/pb_advanced_table/docs/_advanced_table_sort_per_column_for_multi_column.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Sorting on columns can also be applied to columns when using the multi-header variant, however in this case sorting can only be set on leaf columns NOT on parent columns.
|
@@ -29,6 +29,8 @@ examples:
|
|
29
29
|
- advanced_table_default: Default (Required Props)
|
30
30
|
- advanced_table_sort: Enable Sorting
|
31
31
|
- advanced_table_sort_control: Sort Control
|
32
|
+
- advanced_table_sort_per_column: Enable Sort By Column
|
33
|
+
- advanced_table_sort_per_column_for_multi_column: Enable Sort By Column (Multi-Column)
|
32
34
|
- advanced_table_custom_sort: Custom Sort
|
33
35
|
- advanced_table_expanded_control: Expanded Control
|
34
36
|
- advanced_table_expand_by_depth: Expand by Depth
|
@@ -40,4 +40,6 @@ export { default as AdvancedTableColumnStylingColumnHeaders } from './_advanced_
|
|
40
40
|
export { default as AdvancedTableInfiniteScroll} from './_advanced_table_infinite_scroll.jsx'
|
41
41
|
export {default as AdvancedTableWithCustomHeader} from './_advanced_table_with_custom_header.jsx'
|
42
42
|
export { default as AdvancedTableCustomSort } from './_advanced_table_custom_sort.jsx'
|
43
|
-
export { default as AdvancedTableWithCustomHeaderMultiHeader } from './_advanced_table_with_custom_header_multi_header.jsx'
|
43
|
+
export { default as AdvancedTableWithCustomHeaderMultiHeader } from './_advanced_table_with_custom_header_multi_header.jsx'
|
44
|
+
export { default as AdvancedTableSortPerColumn } from './_advanced_table_sort_per_column.jsx'
|
45
|
+
export { default as AdvancedTableSortPerColumnForMultiColumn } from './_advanced_table_sort_per_column_for_multi_column.jsx'
|
@@ -2,7 +2,6 @@ import PbEnhancedElement from "../pb_enhanced_element";
|
|
2
2
|
import { updateSelectionActionBar } from "./advanced_table_action_bar";
|
3
3
|
|
4
4
|
const FLAT_SELECTOR = "[data-flat-advanced-table-select='true']";
|
5
|
-
const SELECT_ALL_SELECTOR = "#select-all-rows input[type='checkbox']";
|
6
5
|
|
7
6
|
export default class PbFlatAdvancedTable extends PbEnhancedElement {
|
8
7
|
static get selector() {
|
@@ -37,9 +36,12 @@ export default class PbFlatAdvancedTable extends PbEnhancedElement {
|
|
37
36
|
}
|
38
37
|
};
|
39
38
|
|
39
|
+
const selectAllId = this.element.getAttribute('data-pb-checkbox-indeterminate-parent')
|
40
|
+
const selectAllSelector = `#${selectAllId} input[type='checkbox']`
|
41
|
+
|
40
42
|
table.addEventListener("change", (e) => {
|
41
43
|
const rowCb = e.target.closest(FLAT_SELECTOR + " input[type='checkbox']");
|
42
|
-
const allCb = e.target.closest(
|
44
|
+
const allCb = e.target.closest(selectAllSelector);
|
43
45
|
if (!rowCb && !allCb) return;
|
44
46
|
|
45
47
|
if (rowCb) {
|
@@ -50,15 +52,6 @@ export default class PbFlatAdvancedTable extends PbEnhancedElement {
|
|
50
52
|
const tr = rowCb.closest("tr");
|
51
53
|
tr?.classList.toggle("bg-row-selection", rowCb.checked);
|
52
54
|
tr?.classList.toggle("bg-white", !rowCb.checked);
|
53
|
-
|
54
|
-
// Sync header checkbox
|
55
|
-
const header = table.querySelector(SELECT_ALL_SELECTOR);
|
56
|
-
if (header) {
|
57
|
-
const all = Array.from(
|
58
|
-
table.querySelectorAll(FLAT_SELECTOR + " input[type='checkbox']")
|
59
|
-
).every((cb) => cb.checked);
|
60
|
-
header.checked = all;
|
61
|
-
}
|
62
55
|
}
|
63
56
|
|
64
57
|
if (allCb) {
|