-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
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.
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 |
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.
// 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]) |
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.
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; | ||
}) |
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.
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)
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 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
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.
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. | ||
*/ |
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.
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.
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.
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?
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.
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.
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) |
@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); |
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 it's nicer to use the type from HttpClient? this.http.get<GithubApi>(requestUrl)
|
||
.mat-column-created { | ||
max-width: 124px; | ||
} |
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.
no newline at end of file
this.exampleDatabase.data.forEach(data => this.selection.select(data.id)); | ||
} | ||
applyFilter(filterValue: string) { | ||
filterValue = filterValue.trim(); // Remove whitespace |
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.
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.
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 think so - I expect most people will want it trimmed and lowercase by default. I'll make another PR that does this.
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.
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; | ||
} | ||
} |
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.
No newline at the end of the file.
@jelbourn These seem like better examples and overall less complicated. |
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.
LGTM
Add merge-ready when ready |
Hi, I noticed that the selection of rows was removed from the examples (table-overview-example) with these changes. |
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. |
Drastically simplifies the examples
@willshowell