Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

andrewseguin
Copy link
Contributor

@andrewseguin andrewseguin commented Oct 31, 2017

@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

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 31, 2017
Copy link
Contributor

@willshowell willshowell left a 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.

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.
Copy link
Contributor

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.

Copy link
Contributor

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>


```ts
const myDataSource = new MatTableDataSource();
myDataSource.data = dataToRender;
Copy link
Contributor

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;

```js
const initialSelection = [];
const allowMultiSelect = true;
const selection = new SelectionModel<MyDataType>(allowMultiSelect, initialSelection);
Copy link
Contributor

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


```html
<ng-container matColumnDef="select">
<mat-header-cell *matHeaderCellDef>
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation off by 1


```css
.mat-column-select {
overflow: initial;
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation off by 1

@andrewseguin
Copy link
Contributor Author

Thanks for the review - made the changes. Wasn't sure what you mean about breaking newlines

Copy link
Contributor

@willshowell willshowell left a 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 👍

will let the table know what columns each row should render.

```html
<mat-header-row *matHeaderRowDef="[‘userName', ‘age']"></mat-header-row>
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ugh, thanks Google Docs

@andrewseguin andrewseguin added the P2 The issue is important to a large percentage of users, with a workaround label Oct 31, 2017

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.
Copy link
Member

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.
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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).
Copy link
Member

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
Copy link
Member

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.

Copy link

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`
Copy link
Member

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)

Copy link

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.

@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants