Skip to content

Mat Sorting on Mat Table calls re-render multiple times #21667

Closed

Description

@AshotAleqs

Reproduction

I am not sure this is a bug, but I think it is wrong. I know the mat table change detection strategy is onPush,
and it will re-render when the datasource reference will be changed, but when you are using mat Sorting on that table, it will re-render the table when you will hover that sortable header, it comes from components/src/material/sort/sort-header.ts file there are 2 events added. to the host

 '(mouseenter)': '_setIndicatorHintVisible(true)',
 '(mouseleave)': '_setIndicatorHintVisible(false)',

info from package.json

  "dependencies": {
    "@angular/animations": "~11.0.5",
    "@angular/cdk": "^11.0.3",
    "@angular/common": "~11.0.5",
    "@angular/compiler": "~11.0.5",
    "@angular/core": "~11.0.5",
    "@angular/forms": "~11.0.5",
    "@angular/material": "^11.0.3",
  },

Here is the simple reproduction example: https://stackblitz.com/edit/stackoverflow-table-example?file=src/app/table-basic-example.ts

Activity

  1. added
    needs triage
    on Jan 21, 2021
  2. changed the title [-]Mat Sorting on Mat Table call re-render multiple times[/-] [+]Mat Sorting on Mat Table cals re-render multiple times[/+] on Jan 21, 2021
  3. changed the title [-]Mat Sorting on Mat Table cals re-render multiple times[/-] [+]Mat Sorting on Mat Table calls re-render multiple times[/+] on Jan 21, 2021
  4. jelbourn commented on Jan 21, 2021

    @jelbourn
    Contributor

    This is working as expected. What you're seeing is not re-rendering, it's Angular calling your value functions to check if anything changed to determine if something needs to be re-rendered. In general, you shouldn't make any assumptions about when or how many time Angular will read the value of your template bindings.

  5. angular-automatic-lock-bot commented on Feb 21, 2021

    @angular-automatic-lock-bot

    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.

  6. locked and limited conversation to collaborators on Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions