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(datatable-body): avoid multiple calculations and update properly on changes #107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Killusions
Copy link

@Killusions Killusions commented Oct 22, 2024

This starts to improve the issues caused by the many setters and getters, while it does not fully solve some of the OnPush issues I encountered, it at least helps with some them.

@Killusions Killusions changed the title fix(datatable-body): avoid multiple calculations and update properly … fix(datatable-body): avoid multiple calculations and update properly on changes Oct 22, 2024
@Killusions Killusions force-pushed the fix/avoid-multiple-calculations-and-update-properly-on-changes-in-datatable-body branch from 2c99d95 to aab60d4 Compare October 22, 2024 15:56
@Killusions Killusions force-pushed the fix/avoid-multiple-calculations-and-update-properly-on-changes-in-datatable-body branch from aab60d4 to 3f4280e Compare October 22, 2024 15:58
@Killusions
Copy link
Author

@chintankavathia It seems due to the bottomSummaryRowsStyles = computed(() the cache is prematurely accessed.

@Killusions
Copy link
Author

@chintankavathia It seems due to the bottomSummaryRowsStyles = computed(() the cache is prematurely accessed.

Just made it wait for it

@Killusions
Copy link
Author

@chintankavathia Before I go ahead here, can you check if it conflicts with something?

Copy link
Member

@chintankavathia chintankavathia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Killusions some of things here would conflict with some of the refactoring which I am currently doing. I was wondering instead of replacing setters with ngOnChanges we wait for angular v19 which is just few weeks away and then switch to signal inputs, what do you think? We anyway agreed to bump to v19 before we do the major release.

<div
class="datatable-row-{{ colGroup.type }} datatable-row-group"
[ngStyle]="_groupStyles[colGroup.type]"
[ngStyle]="groupStyles[colGroup.type]"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +490 to +525
private updateColumnsByPin() {
this._columnsByPin = columnsByPinArr(this.columns);
}

private updateGroupStyles() {
this._groupStyles.left = this.calcStylesByGroup('left');
this._groupStyles.center = this.calcStylesByGroup('center');
this._groupStyles.right = this.calcStylesByGroup('right');
this.cd.markForCheck();
}

private calcStylesByGroup(group: 'left' | 'right' | 'center') {
const widths = this.columnGroupWidths;
const offsetX = this.offsetX;

if (group === 'left') {
return {
width: `${widths[group]}px`,
...translateXY(offsetX, 0)
};
} else if (group === 'right') {
const bodyWidth = this.innerWidth;
const totalDiff = widths.total - bodyWidth;
const offsetDiff = totalDiff - offsetX;
const offset =
(offsetDiff + (this.verticalScrollVisible ? this.scrollbarHelper.getWidth() : 0)) * -1;
return {
width: `${widths[group]}px`,
...translateXY(offset, 0)
};
}

return {
width: `${widths[group]}px`
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will not be needed with #106

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chintankavathia Makes sense, but the main part of this still stands, which is to avoid doing calculations in every row and doing them shared in the body component instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants