Skip to content

DataTable.rowSelect is fired on DataTableRow.ngOnDestroy #27

@peter-gergely-horvath

Description

@peter-gergely-horvath

The logic in DataTableRow unselects the row when it is being destroyed. This causes spurious row selection events with nulls.

export class DataTableRow implements OnDestroy {

    // ..

    ngOnDestroy() {
        this.selected = false;
    }
    // ..

}

This causes the DataTableRow.selectedChange EventEmitter fire:

this.selectedChange.emit(selected);

    set selected(selected) {
        this._selected = selected;
        this.selectedChange.emit(selected);
    }

This behavior causes spurious row selection events to be fired in case the component hosting the grid is being destroyed.

This is problematic, in case the grid selection is used somewhere else as well, outside of the component hosting the grid.

For example you could have a case, where you implement the grid to select something and then the selection is used on another screen. The grid selection is stored in a dedicated service external to the component, to be used for the next step of a wizard.

When the component used to host the grid is being destroyed, the grid fires DataTableRow.selectedChange with null.

By default, the listener cannot distinguish if the un-selection was performed by the user, by un-selecting the previously selected item, or by the grid row destruction logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions