Skip to content
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

feat(table): add the ability to show a data row when no data is available #18041

Merged
merged 1 commit into from
Apr 20, 2020

Conversation

crisbeto
Copy link
Member

As the table is set up at the moment, there's no convenient way to show the user something when their filtered table didn't match any data. These changes add a new directive that renders out a single row when no other data is available which can be used to show a message.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release labels Dec 25, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 25, 2019

/** Row that can be used to display a message when no data is shown in the table. */
@Directive({
selector: 'ng-template[cdkNoDataRow]'
Copy link
Member Author

Choose a reason for hiding this comment

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

The name of the directive sounds a little clunky, but I couldn't come up with anything more descriptive. I'm open ideas on how to name it better.

Copy link
Contributor

@ccjmne ccjmne Dec 25, 2019

Choose a reason for hiding this comment

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

The term "placeholder" comes to (my) mind but I'm not sure it'd be adequate here.

I'd somewhat like to have all the elements that are "placeholders" of some sort identified as such across all the components that use them. Not just all the placeholders in particular, but all the elements that are (semantically) somewhat agnostic to the "collection" they belong to in general.

A reusable naming convention makes for a conceptually simpler API!

I think the CDK Drag&Drop uses something like cdkDragPlaceholder, so maybe cdkNoDataPlaceholder would be acceptable... but I don't like it, it's clunkier than cdkNoDataRow ever was 🤪

Disclaimer: I really haven't thought this through, this is just my two cents.

Copy link
Member Author

Choose a reason for hiding this comment

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

Having "placeholder" in there sounds good to me since this behaves a little bit like the native input placeholder (e.g. something that shows up when the input is empty).

@jelbourn
Copy link
Member

I'm not totally sold that we'd want to add this to the table. You can accomplish the same thing today by:

  • Have the data source emit a placeholder value when the data would be empty
  • Use the when property on the row definition to show whatever for that placeholder

We could explicitly document this pattern without needing to add any additional code or concepts to the table.

@crisbeto
Copy link
Member Author

How would you handle the placeholder row having a different amount of cells compared to regular rows? You don't need a full row of cells just to say "No more data".

@jelbourn
Copy link
Member

jelbourn commented Jan 13, 2020

I was thinking something like this

<table mat-table [dataSource]="dataSource">

  <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef>Name</th>
    <td mat-cell *matCellDef="let element">{{item.name}}</td>
  </ng-container>

  <!-- ... other data columns ... -->

  <!-- Empty data placeholder -->
  <ng-container matColumnDef="empty-placeholder">
    <td mat-cell *matCellDef colspan="3">No results found</td>
  </ng-container>

  <tr mat-header-row *matHeaderRowDef="['name', 'age', 'address']"></tr>
  <tr mat-row *matRowDef="let row; columns: ['name', 'age', 'address'];"></tr>
  <tr mat-row *matRowDef="let row; columns: ['empty-placeholder']; when: isEmptyRow"></tr>
</table>

We can chat about it during this week's team meeting

@jelbourn
Copy link
Member

Based on discussion, we will go ahead with this. I propose using matEmptyDataRowDef or matEmptyPlaceholderRowDef

@crisbeto
Copy link
Member Author

@jelbourn I've changed the naming to matEmptyPlaceholderRowDef.

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, just needs rebase

src/cdk/table/row.ts Show resolved Hide resolved
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Feb 4, 2020
@crisbeto
Copy link
Member Author

crisbeto commented Feb 4, 2020

Rebased.

@quanterion
Copy link
Contributor

any updates?

…able

As the table is set up at the moment, there's no convenient way to show the user something when their filtered table didn't match any data. These changes add a new directive that renders out a single row when no other data is available which can be used to show a message.
@jelbourn jelbourn merged commit e512581 into angular:master Apr 20, 2020
chenlijun99 added a commit to chenlijun99/components that referenced this pull request Apr 20, 2020
soro-google pushed a commit to soro-google/components that referenced this pull request Apr 24, 2020
…able (angular#18041)

As the table is set up at the moment, there's no convenient way to show the user something when their filtered table didn't match any data. These changes add a new directive that renders out a single row when no other data is available which can be used to show a message.
@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 May 21, 2020
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 P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants