Skip to content

feat(table): support native table selectors - #10594

Merged
josephperrott merged 3 commits into
angular:masterfrom
andrewseguin:table-native-html
Mar 30, 2018
Merged

feat(table): support native table selectors#10594
josephperrott merged 3 commits into
angular:masterfrom
andrewseguin:table-native-html

Conversation

@andrewseguin

@andrewseguin andrewseguin commented Mar 27, 2018

Copy link
Copy Markdown
Contributor

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 Label used to distinguish feature request from other issues pr: needs review target: minor This PR is targeted for the next minor release labels Mar 27, 2018
@andrewseguin
andrewseguin requested a review from amcdnl as a code owner March 27, 2018 22:18
@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
Comment thread src/cdk/table/table.ts Outdated
}

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Prefer nodeName to tagName

Comment thread src/cdk/table/table.ts Outdated
/** 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
Copy Markdown
Contributor

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

Comment thread src/lib/table/table.md Outdated
`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
Copy Markdown
Contributor

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

Comment thread src/lib/table/table.md Outdated
### 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
Copy Markdown
Contributor

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
Copy Markdown
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

jainankit102 commented May 28, 2018

Copy link
Copy Markdown

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

CDDelta commented May 28, 2018

Copy link
Copy Markdown

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

@jainankit102

Copy link
Copy Markdown

@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

CDDelta commented May 29, 2018

Copy link
Copy Markdown

@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
Copy Markdown

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

@angular-automatic-lock-bot

Copy link
Copy Markdown

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 Label used to distinguish feature request from other issues 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