angular-5-data-table icon indicating copy to clipboard operation
angular-5-data-table copied to clipboard

DataTable.rowSelect is fired on DataTableRow.ngOnDestroy

Open peter-gergely-horvath opened this issue 7 years ago • 0 comments

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

https://github.com/ggmod/angular-5-data-table/blob/6efd247cb353dbf78350dfeb3f6643394bcfa178/src/app/data-table/components/row.ts#L53

export class DataTableRow implements OnDestroy {

    // ..

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

}

This causes the DataTableRow.selectedChange EventEmitter fire:

https://github.com/ggmod/angular-5-data-table/blob/6efd247cb353dbf78350dfeb3f6643394bcfa178/src/app/data-table/components/row.ts#L30

    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.

peter-gergely-horvath avatar Jun 01 '18 08:06 peter-gergely-horvath