Skip to content

Commit bd1a775

Browse files
authored
Merge pull request #1286 from ferishili/issue-1250
Deselect table rows when sorting
2 parents 0548378 + b40787e commit bd1a775

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/shared/Table.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const Table = ({
8686
// State of dropdown menu
8787
const [showPageSizes, setShowPageSizes] = useState(false);
8888
const editTableViewModalRef = useRef<ModalHandle>(null);
89+
const selectAllCheckboxRef = useRef<HTMLInputElement>(null);
8990

9091
useEffect(() => {
9192
// Function for handling clicks outside of an open dropdown menu
@@ -128,6 +129,8 @@ const Table = ({
128129
};
129130

130131
const sortByColumn = (colName: string) => {
132+
// By sorting, any selected item has to be deselected!
133+
forceDeselectAll();
131134
dispatch(setSortBy(colName));
132135
let direction: ReverseOptions = "ASC";
133136
if (reverse && reverse === "ASC") {
@@ -137,6 +140,13 @@ const Table = ({
137140
dispatch(updatePages());
138141
};
139142

143+
const forceDeselectAll = () => {
144+
dispatch(changeAllSelected(false));
145+
if (selectAllCheckboxRef.current?.checked) {
146+
selectAllCheckboxRef.current.checked = false;
147+
}
148+
}
149+
140150
const showEditTableViewModal = async () => {
141151
editTableViewModalRef.current?.open()
142152
};
@@ -186,6 +196,7 @@ const Table = ({
186196
<th className="small">
187197
{/*Checkbox to select all rows*/}
188198
<input
199+
ref={selectAllCheckboxRef}
189200
type="checkbox"
190201
onChange={(e) => onChangeAllSelected(e)}
191202
aria-label={t("EVENTS.EVENTS.TABLE.SELECT_ALL")}

0 commit comments

Comments
 (0)