Skip to content

docs(table): change docs to use MatTableDataSource #8007

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

Merged
merged 3 commits into from
Oct 27, 2017

Conversation

andrewseguin
Copy link
Contributor

Drastically simplifies the examples

@willshowell

@andrewseguin andrewseguin added P2 The issue is important to a large percentage of users, with a workaround pr: needs review labels Oct 24, 2017
@andrewseguin andrewseguin requested a review from jelbourn October 24, 2017 20:24
@andrewseguin andrewseguin requested a review from amcdnl as a code owner October 24, 2017 20:24
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 24, 2017
@andrewseguin andrewseguin changed the title chore(table): change docs to use MatTableDataSource docs(table): change docs to use MatTableDataSource Oct 24, 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.

Only minor nits.

It's hard to tell, but this removes all custom data source examples, right? Would it be valuable in a follow up PR to demo implementing your own data source?

});
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace
filterValue = filterValue.toLowerCase(); // Datasource defaults to lowercase matches
Copy link
Contributor

Choose a reason for hiding this comment

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

// MatTableDataSource defaults to lowercase matches?

// If the user changes the sort order, reset back to the first page.
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);

Observable.merge(...[this.sort.sortChange, this.paginator.page])
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be simpler to just do,

Observable.merge(this.sort.sortChange, this.paginator.page)

since you're no longer defining displayDataChanges

this.resultsLength = data.total_count

return data.items;
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be more idiomatic to place inside do? Or would that just end up more confusing 🤷‍♂️?

.do(data => {
  // Flip flag to show that loading has finished.
  this.isLoadingResults = false;
  this.isRateLimitReached = false;
  this.resultsLength = data.total_count;
})
.map(data => data.items)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like do better here but concerned that adding more operators will distract people. Hard balance to find since people will probably copy/paste this =P

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, agreed on it being distracting. map works just as well since you still do have to map it to items.

/**
* Set the paginator and sort after the view has been initialized so
* that the components are completely set up for the data source to access.
*/
Copy link
Contributor

@willshowell willshowell Oct 25, 2017

Choose a reason for hiding this comment

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

Is there any other way to word this? "...so that the components are completely set up..." kind of glosses over why it has to be here instead of in, say, OnInit.

Maybe

Set the paginator and sort after the view has been initialized since that is
the first time the component has access to the ViewChild queries.

Copy link
Contributor Author

@andrewseguin andrewseguin Oct 25, 2017

Choose a reason for hiding this comment

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

Changed to

Set the sort after the view init since this component will be able to query its view for the initialized sort.

Think that's alright?

Copy link
Contributor

Choose a reason for hiding this comment

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

Wait until after the view init to set the paginator and sort in the data source. This will enable the component to query its view for the initialized paginator and sort components.

Maybe an improvement? I guess it doesn't really matter, and I think having any comment at all should signify that it's important to keep it there after the copy-paste.

@andrewseguin
Copy link
Contributor Author

Made the suggested changes, thanks for the thorough review! I'm currently in the process of revamping the docs, and I'll share the doc with you for suggestions on what should be included (like a custom data source)

@jelbourn
Copy link
Member

@ErinCoughlan how do these example changes look to you?


return this._httpClient.get<GithubApi>(requestUrl);
return this.http.get(requestUrl)
.map(response => response as GithubApi);

Choose a reason for hiding this comment

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

Maybe it's nicer to use the type from HttpClient? this.http.get<GithubApi>(requestUrl)


.mat-column-created {
max-width: 124px;
}
Copy link

@ErinCoughlan ErinCoughlan Oct 26, 2017

Choose a reason for hiding this comment

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

no newline at end of file

this.exampleDatabase.data.forEach(data => this.selection.select(data.id));
}
applyFilter(filterValue: string) {
filterValue = filterValue.trim(); // Remove whitespace

Choose a reason for hiding this comment

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

Does it make sense to add the trim and toLowerCase into the MatTableDataSource? It's not intuitive as a user that either of these would be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so - I expect most people will want it trimmed and lowercase by default. I'll make another PR that does this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR #8059 created to address this - data source's entire filter matching function can be overriden and by default it will lowercase/trim

color: black;
}
}

Choose a reason for hiding this comment

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

No newline at the end of the file.

@ErinCoughlan
Copy link

@jelbourn These seem like better examples and overall less complicated.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn
Copy link
Member

Add merge-ready when ready

@andrewseguin andrewseguin added the action: merge The PR is ready for merge by the caretaker label Oct 26, 2017
@mmalerba mmalerba merged commit e15fc0b into angular:master Oct 27, 2017
@wk-done
Copy link

wk-done commented Oct 31, 2017

Hi, I noticed that the selection of rows was removed from the examples (table-overview-example) with these changes.
If I'm not completely wrong it was the only example out there how to use selection in the data-table. Is there an other example page or will there be one in the future?

@andrewseguin andrewseguin deleted the table-update-examples branch November 28, 2017 20:39
@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
action: merge The PR is ready for merge by the caretaker 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.

8 participants