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

feat(table): support native table selectors #10594

Merged
merged 3 commits into from
Mar 30, 2018

Conversation

andrewseguin
Copy link
Contributor

@andrewseguin andrewseguin commented Mar 27, 2018

Summary:
Add native table selectors to the CdkTable (e.g. <table cdk-table>) and refocuses the docs on this approach as the primary way of using the table components

Fixes #6058, #7964, #9027, #8680
Closes #5888, #5866

Full Description:
Add the ability to render the table using the native HTML table element as opposed to using the flex-based <mat-table> element. This quickly enables key features such as auto column resizing, col/row span, easy copy/paste (cells map into spreadsheets easily). Also, any native table can become a material table by simply applying the mat-table class (+ classes to rows/cells).

Benefits to using native table:

  • More intuitive approach - use table elements
  • Auto-resizing columns
  • Colspan and rowspan
  • Ability to copy/paste cells into spreadsheets
  • Better sticky positioning support
  • Increased a11y support (aria + <table>)
  • CdkTable supports a table appearance out of the box (no need for additional styling)
  • Header/footer sections show up on all pages if printed
  • Better horizontal scrolling (flex doesn't stretch the row styling easily)

@andrewseguin andrewseguin added feature This issue represents a new feature or feature request rather than a bug or bug fix pr: needs review target: minor This PR is targeted for the next minor release labels Mar 27, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 27, 2018
@andrewseguin andrewseguin force-pushed the table-native-html branch 3 times, most recently from 7acb55d to da35122 Compare March 29, 2018 18:14
}
}

ngOnInit() {
if (this._elementRef.nativeElement.tagName === 'TABLE') {
Copy link
Member

Choose a reason for hiding this comment

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

Prefer nodeName to tagName

/** Adds native table sections (e.g. tbody) and moves the row placeholders into them. */
private _applyNativeTableSections() {
const tHeadEl = document.createElement('thead');
const tBodyEl = document.createElement('tbody');
Copy link
Member

Choose a reason for hiding this comment

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

Just thead and tbody since that's the tag name; it's weird as camelCase

@@ -278,3 +278,50 @@ Table's default role is `grid`, and it can be changed to `treegrid` through `rol

`mat-table` does not manage any focus/keyboard interaction on its own. Users can add desired
focus/keyboard interactions in their application.

### Using flex layout
Copy link
Member

Choose a reason for hiding this comment

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

Reword this to be something like Tables with `display: flex so that it's not confused with @angular/flex-layout

### Using flex layout

The `MatTable` does not require that you use a native HTML table. Instead, you can use an
alternative approach that uses flex-layout for the table's styles.
Copy link
Member

Choose a reason for hiding this comment

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

display: flex

@andrewseguin
Copy link
Contributor Author

Thanks - updated with the comments applied

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Mar 29, 2018
@jainankit102
Copy link

jainankit102 commented May 28, 2018

Can you please give us a stackblitz example for this. Having difficulty to implement native table with rowspan as a material table.

Sample code is also more then enough.

Thanks in advance.

@CDDelta
Copy link

CDDelta commented May 28, 2018

@jainankit102 check material.angular.io. it's all there.

@jainankit102
Copy link

@CDDelta thanks for that but I already checked in material.angular.io. didn't found any example regarding material table with rowspan and colspan.

Thanks

@CDDelta
Copy link

CDDelta commented May 29, 2018

@jainankit102 sorry it was early in the morning, I didn't notice you were looking for rowspan examples. I recommend you open a new issue about this, you would be more likely to get responses.

@jainankit102
Copy link

Thanks @CDDelta for the help. I have raised the ticket for that i.e. #11551

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement feature This issue represents a new feature or feature request rather than a bug or bug fix target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Table] Columns get misaligned in dense tables [Table] Add a colspan input for columns
6 participants