Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Selection checkbox state was not updated after data in the table was changed #2265

Merged
merged 3 commits into from Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,9 +26,11 @@ export const DataViewHeaderButton: React.FC<{
isHidden?: boolean;
disabled?: boolean;
title?: string;
id?: string;
onClick?(event: any): void;
}> = (props) => (
<button
id={props.id}
title={props.title}
ref={props.domRef}
className={cx(props.disabled ? S.disabled : S.enabled, S.root, {hidden: props.isHidden})}
Expand Down
Expand Up @@ -51,6 +51,7 @@ export class DataViewHeaderButtonGroup extends React.Component<{
<Observer key={action.id}>
{() => (
<DataViewHeaderButton
id={action.id}
title={action.caption}
disabled={!getIsEnabledAction(action)}
onClick={() => setDropped(true)}
Expand Down Expand Up @@ -85,6 +86,7 @@ export class DataViewHeaderButtonGroup extends React.Component<{
<Observer key={action.id}>
{() => (
<DataViewHeaderButton
id={action.id}
title={action.caption}
onClick={(event) => uiActions.actions.onActionClick(action)(event, action)}
disabled={!getIsEnabledAction(action)}
Expand Down
12 changes: 12 additions & 0 deletions frontend-html/src/model/entities/DataView.ts
Expand Up @@ -313,6 +313,18 @@ export class DataView implements IDataView {
this.selectAllCheckboxChecked = false;
}

updateSelectedIds() {
const currentRowIds = this.dataTable.rows
.map(row => this.dataTable.getRowId(row));
for (let rowId of Array.from(this.selectedRowIds)) {
if (!currentRowIds.includes(rowId)) {
this.selectedRowIds.delete(rowId);
}
}
this.selectAllCheckboxChecked = currentRowIds.length > 0
&& currentRowIds.every(rowId => this.selectedRowIds.has(rowId));
}

@action.bound
clear() {
this.selectedRowIds.clear();
Expand Down
1 change: 1 addition & 0 deletions frontend-html/src/model/entities/ListRowContainer.ts
Expand Up @@ -137,6 +137,7 @@ export class ListRowContainer implements IRowsContainer {
}
self.sortedIds = rows.map(row => self.rowIdGetter(row));
const dataView = getDataView(self);
dataView.updateSelectedIds();
if (!data?.retainPreviousSelection) {
dataView.reselectOrSelectFirst();
}
Expand Down
2 changes: 2 additions & 0 deletions frontend-html/src/model/entities/types/IDataView.ts
Expand Up @@ -206,6 +206,8 @@ export interface IDataView extends IDataViewData {

isLazyLoading: Boolean;

updateSelectedIds(): void;

insertRecord(index: number, row: any[], shouldLockNewRowAtTop?: boolean): Promise<any>;
}

Expand Down