Skip to content

Commit cf0b389

Browse files
committed
fix(AnalyticalTable): control row-selection explicitly by setting selectRowIds
1 parent 6882524 commit cf0b389

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.stories.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ import { FlexBoxJustifyContent } from '@ui5/webcomponents-react/lib/FlexBoxJusti
9292
groupable: true,
9393
groupBy: [],
9494
rowHeight: 44,
95-
selectedRowIds: { 3: true },
95+
selectedRowIds: undefined,
9696
withRowHighlight: true,
9797
highlightField: 'status',
9898
infiniteScroll: true,

packages/main/src/components/AnalyticalTable/hooks/useSingleRowStateSelection.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@ const getRowProps = (rowProps, { row, instance }) => {
5656
if (selectionBehavior === TableSelectionBehavior.ROW_SELECTOR && !selectionCellClick) {
5757
return;
5858
}
59-
60-
if (selectionMode === TableSelectionMode.SINGLE_SELECT) {
61-
for (const row of selectedFlatRows) {
62-
toggleRowSelected(row.id, false);
59+
if (!webComponentsReactProperties.selectedRowIds) {
60+
if (selectionMode === TableSelectionMode.SINGLE_SELECT) {
61+
for (const row of selectedFlatRows) {
62+
toggleRowSelected(row.id, false);
63+
}
6364
}
65+
instance.toggleRowSelected(row.id);
6466
}
65-
instance.toggleRowSelected(row.id);
6667

6768
// fire event
6869
if (typeof onRowSelected === 'function') {

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,8 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
207207
totalColumnsWidth,
208208
toggleRowSelected,
209209
toggleAllRowsSelected,
210-
setGroupBy
210+
setGroupBy,
211+
initialState
211212
} = useTable(
212213
{
213214
columns,
@@ -232,7 +233,8 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
232233
scaleWidthMode,
233234
loading,
234235
withRowHighlight,
235-
highlightField
236+
highlightField,
237+
selectedRowIds
236238
},
237239
...reactTableOptions
238240
},
@@ -282,14 +284,16 @@ const AnalyticalTable: FC<TableProps> = forwardRef((props: TableProps, ref: Ref<
282284
}, [groupBy, setGroupBy]);
283285

284286
useEffect(() => {
285-
toggleAllRowsSelected(false);
286-
const validChars = /^\d+(\.\d+)*$/;
287-
// eslint-disable-next-line guard-for-in
288-
for (const row in selectedRowIds) {
289-
if (reactTableOptions?.getRowId) {
290-
toggleRowSelected(row, selectedRowIds[row]);
291-
} else if (validChars.test(row)) {
292-
toggleRowSelected(row, selectedRowIds[row]);
287+
if (selectedRowIds) {
288+
toggleAllRowsSelected(false);
289+
const validChars = /^\d+(\.\d+)*$/;
290+
// eslint-disable-next-line guard-for-in
291+
for (const row in selectedRowIds) {
292+
if (reactTableOptions?.getRowId) {
293+
toggleRowSelected(row, selectedRowIds[row]);
294+
} else if (validChars.test(row)) {
295+
toggleRowSelected(row, selectedRowIds[row]);
296+
}
293297
}
294298
}
295299
}, [toggleRowSelected, toggleAllRowsSelected, selectedRowIds, reactTableOptions?.getRowId]);
@@ -485,7 +489,6 @@ AnalyticalTable.defaultProps = {
485489
visibleRows: 15,
486490
subRowsKey: 'subRows',
487491
highlightField: 'status',
488-
selectedRowIds: {},
489492
onGroup: () => {},
490493
onRowExpandChange: () => {},
491494
onColumnsReordered: () => {},

0 commit comments

Comments
 (0)