-
Notifications
You must be signed in to change notification settings - Fork 6.8k
docs(table): updated docs for the table #8162
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
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.
- Break newlines?
- The single quotes look styled from copy-paste. I dunno if that matters, but it looks out of place in the code blocks.
src/lib/table/table.md
Outdated
data. | ||
The `mat-table` provides a Material Design styled data-table that can be used to display rows of data. | ||
|
||
The table’s template is made up of column definitions where each definition provides the content for that column’s header and row cells. It also includes a `mat-header-row` and `mat-row` where each takes an ordered list of the columns they should render out. |
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.
Maybe
...they should render.
or
...they should stamp out.
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.
Also consider making <mat-header-row>
and <mat-row>
src/lib/table/table.md
Outdated
|
||
```ts | ||
const myDataSource = new MatTableDataSource(); | ||
myDataSource.data = dataToRender; |
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.
Change to emphasize the data source is a class property?
this.myDataSource = new MatTableDataSource();
this.myDataSource.data = dataToRender;
src/lib/table/table.md
Outdated
```js | ||
const initialSelection = []; | ||
const allowMultiSelect = true; | ||
const selection = new SelectionModel<MyDataType>(allowMultiSelect, initialSelection); |
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.
Same thing here since selection
should be a class property
src/lib/table/table.md
Outdated
|
||
```html | ||
<ng-container matColumnDef="select"> | ||
<mat-header-cell *matHeaderCellDef> |
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.
Indentation off by 1
src/lib/table/table.md
Outdated
|
||
```css | ||
.mat-column-select { | ||
overflow: initial; |
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.
Indentation off by 1
Thanks for the review - made the changes. Wasn't sure what you mean about breaking newlines |
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.
Oops yeah I just meant to break the lines around 100 columns 👍
src/lib/table/table.md
Outdated
will let the table know what columns each row should render. | ||
|
||
```html | ||
<mat-header-row *matHeaderRowDef="[‘userName', ‘age']"></mat-header-row> |
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.
Looks like only the closing ones have changed. There are a few remaining opening single-quotes that are styled.
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.
Ugh, thanks Google Docs
|
||
The table's template is made up of column definitions where each definition provides the content for | ||
that column's header and row cells. It also includes a `<mat-header-row>` and `<mat-row>` where each | ||
takes an ordered list of the columns they should render. |
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 would rephrase this paragraph a bit
The table's template consists of two parts: column definitions and row
definitions. Each column definition contains templates for that column's
header and content cells. Each row definition captures the columns used
for that row and any bindings applied to the row element.
providing an Observable that emits an array of data. The table picks up this data array and writes | ||
a `mat-row` for each data object in the array. It is the responsibility of the `DataSource` to send | ||
exactly what data should be rendered by the table, so any data manipulation features such as | ||
sorting or filtering should be implemented here. |
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.
Trying to tighten the language a bit, avoiding passive voice:
A `DataSource` provides data to the table by emitting an `Observable` stream of
the items to be rendered. Each emit includes the _entire set of items_ that being
displayed. The table, listening to this stream, will render a row per item. Any
manipulation of the data being displayed (e.g. sorting, pagination, filtering)
should be captured by the `DataSource`, ultimately emitting a new set of
items to reflect any changes.
<!-- example(table-basic) --> | ||
|
||
### Features | ||
Start by writing your table's column definitions. Each column definition should be given a unique |
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.
Would numbered subheaders help here?
#### 1. Define the table's columns
...
#### 2. Define the table's rows
...
#### 3. Provide data
...
<mat-row *matRowDef="let myRowData; columns: ['userName', 'age']"></mat-row> | ||
``` | ||
|
||
Once your template is set up, the final step is to provide data to the table. This must be done |
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.
Maybe something like
The column and row definitions now capture _how_ data will render- all that's
left is to provide the data itself. For simple scenarios with client-side operations,
`MatTableDataSource` offers a quick and easy starting point. Simply create an
instance of `MatTableDataSource` and set the items to be displayed to the
`data` property. For more advanced scenarios, applications will implement
one or more custom `DataSource` to capture more specific behaviors.
changes made by the user and send the right paged data to the table. | ||
|
||
For more information on using and configuring the `<mat-paginator>`, check out the | ||
[mat-paginator docs](https://material.angular.io/components/paginator/overview). |
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.
We should mention here that mat-paginator
is just one option. The table can work with any paginator control or any pagination strategy.
(same for sorting, filtering, and selection)
While Angular Material does not offer a specific component for filtering tabular data, the table's | ||
data source can be updated based on any custom filter UI. Any filtering pattern need only trigger | ||
an update via the table's data source. | ||
To remove filtered rows from the table's data, simply provide the filter string to the |
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.
This section is too specifically about the MatTableDataSource
. We should mention that we don't provide any filtering UI components and that filtering is up to the app. Then MatTableDataSource
can be the "if you want something simple" extra thing.
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.
Flexibility is great, but this documentation is under angular/material2. Most developers won't have time to try a lot of different options. Would still be good to provide example code for MatTableDataSource.
and selection). | ||
#### Selection | ||
|
||
To add row selection to the table, first set up a `SelectionModel` from `@angular/cdk/collections` |
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.
Same comment here about specificity- I want to keep it clear that users can do selection however they want. If we present it as "this is the way you are supposed to do selection", it begs the question as to why it's not just built in. I would really rather include this in an example with explanation that say "Here is the One True Way to do selection" (same for filtering)
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.
Flexibility is nice, but most developers are just going to want a working example they can start with.
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. |
@willshowell
To be added later: expanding rows (using when predicate), customizing column widths, adding/removing data, dynamic columns (add/remove/move), trackBy
Re-opened PR at #8770