-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(data-table): add row context #5219
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
Conversation
@@ -42,4 +43,8 @@ export class DataTableDemo { | |||
this.propertiesToDisplay.splice(colorColumnIndex, 1); | |||
} | |||
} | |||
|
|||
toggleHighlight(property: string, enable: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any -> boolean
enableRowContextClasses = false; | ||
enableCellContextClasses = false; | ||
|
||
@ViewChild(CdkTable) table: CdkTable<TestData>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm totally blanking on why ViewChild is needed for this example. Can you remind me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, either a copy-paste problem or eventually didn't need the table in the tests. Thanks!
// rows to be added, removed, or moved. The view container contains the same context | ||
// that was provided to each of its cells. | ||
for (let index = 0, count = viewContainer.length; index < count; index++) { | ||
const viewRef = <EmbeddedViewRef<CdkCellOutletRowContext<T>>> viewContainer.get(index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the as
typecast syntax
src/lib/core/data-table/row.ts
Outdated
get even(): boolean { return this.index % 2 === 0; } | ||
|
||
/** True if this cell is contained in a row with an odd-numbered index. */ | ||
get odd(): boolean { return !this.even; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be set statically; getters and setters generate a lot of code, so it's better to avoid them when they're not necessary
Made changes, thanks for the review |
src/lib/core/data-table/row.ts
Outdated
@@ -89,6 +89,29 @@ export class CdkRowDef extends BaseRowDef { | |||
} | |||
} | |||
|
|||
/** Context provided to the row cells */ | |||
export class CdkCellOutletRowContext<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this an interface now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
src/lib/core/data-table/row.ts
Outdated
@@ -89,6 +89,29 @@ export class CdkRowDef extends BaseRowDef { | |||
} | |||
} | |||
|
|||
/** Context provided to the row cells */ | |||
export class CdkCellOutletRowContext<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
d8e75ac
to
d359ca1
Compare
Converted to an interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds index, count, first, last, even, odd to the row context for rows and cells