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

perf(data-table): make checkbox state check more performant #777

Merged
merged 1 commit into from
Jul 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions src/platform/core/data-table/data-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,14 @@ export class TdDataTableComponent implements ControlValueAccessor, AfterContentI
if (this.isRowSelected(row)) {
toggledRows.push(row);
}
row = this._value.filter((val: any) => {
return this.compareWith(row, val);
})[0];
let index: number = this._value.indexOf(row);
if (index > -1) {
this._value.splice(index, 1);
}
});
this.clearModel();
this._allSelected = false;
this._indeterminate = false;
}
Expand Down Expand Up @@ -597,38 +603,23 @@ export class TdDataTableComponent implements ControlValueAccessor, AfterContentI
}
}
this._calculateCheckboxState();
this.onRowSelect.emit({row: row, selected: this.isRowSelected(row)});
this.onRowSelect.emit({row: row, selected: !wasSelected});
this.onChange(this._value);
}

/**
* Calculate all the state of all checkboxes
*/
private _calculateCheckboxState(): void {
this._calculateAllSelected();
this._calculateIndeterminate();
}

/**
* Checks if all visible rows are selected.
*/
private _calculateAllSelected(): void {
const match: string =
this._data ? this._data.find((d: any) => !this.isRowSelected(d)) : true;
this._allSelected = typeof match === 'undefined';
}

/**
* Checks if all visible rows are selected.
*/
private _calculateIndeterminate(): void {
this._indeterminate = false;
if (this._data) {
this._allSelected = typeof this._data.find((d: any) => !this.isRowSelected(d)) === 'undefined';
this._indeterminate = false;
for (let row of this._data) {
if (!this.isRowSelected(row)) {
continue;
}
this._indeterminate = true;
break;
}
}
}
Expand Down