components icon indicating copy to clipboard operation
components copied to clipboard

[Table] MatTableDataSource constructor should include MatSort, MatPaginator

Open JaxonWright opened this issue 9 years ago • 7 comments

Bug, feature request, or proposal:

feature request

What is the expected behavior?

Have a constructor that, at least optionally, takes a MatSort and/or a MatPaginator as parameters.

What is the current behavior?

Currently, you have to create a new MatTableDataSource with only data as a parameter. However, you always have to set the matSort and paginator of the MatTableDataSource after construction. I had to make a class that extends this class to have this, which seems superfluous.

What are the steps to reproduce?

What is the use-case or motivation for changing an existing behavior?

To make the creation of MatTableDataSources easier.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 5.0.1 Material: 5.0.0-rc0 OS: Windows 10 Pro TypeScript: 2.6.1 Browser: Google Chrome 62.0.3202.94 (Official Build) (64-bit)

Is there anything else we should know?

JaxonWright avatar Nov 17 '17 19:11 JaxonWright

Potentially a breaking change, needs discussion

jelbourn avatar Nov 18 '17 00:11 jelbourn

I am facing a similar issue. I am generating data Dynamically, and displaying it in Data Table, but I`m unable to link Paginator with the data table. Data is getting displayed in the table. Following is the sample code snippet (also attaching it ):

  sCollectionList = null;
  dataSource = new MatTableDataSource<object>(this.sCollectionList);
  displayedColumns: string[] = [];

  // SCollectionService Holds my custom HTTP methods //
  constructor(private stColServ: SCollectionService) {
  }
  

// Calling it when a Button from UI is clicked //
  submitFilter() {
  
    // stFilter is a valid objet which is getting passed to my custom post request// 
    this.stColServ.stationFilter(this.stFilter).subscribe(
      data => {
      this.sCollectionList = data;
        
      this.displayedColumns = ['System Data' , 'Product Identifer' , 'Collected Date' , 'No Stations ?' , 'No Smnp ?', 'Export'];
this.dataSource.data = this.sCollectionList;

//      this.streamOfDataUpdates.subscribe(newData => this.dataSource.data = this.sCollectionList);
      this.dataSource.paginator = this.paginator;
      },
    );

  }


  @ViewChild(MatPaginator) paginator: MatPaginator;
  
  /**
   * Set the paginator after the view init since this component will
   * be able to query its view for the initialized paginator.
   */
 ngAfterViewInit() {
      this.dataSource.paginator = this.paginator;
  }

SampleCode.txt

RahulKesarwani avatar Nov 27 '17 07:11 RahulKesarwani

The reason for it not being a part of the constructor is because I didn't want to confuse users into thinking they could use their view children for the MatSort and MatPaginator before the view is initialized. Maybe we can add them as params but then I'd like to set it up so that the paginator and sort notify the data source when they're ready

andrewseguin avatar Nov 27 '17 19:11 andrewseguin

Sorry to say this, but in my opinion this whole mat-table component is buggy and only semi functional to say the least.

noah-fernandes avatar Nov 21 '18 08:11 noah-fernandes

Ek bedoel regtig... Basics bois!

BlindChickens avatar Jul 29 '20 20:07 BlindChickens

Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

Find more details about Angular's feature request process in our documentation.

angular-robot[bot] avatar Feb 01 '22 18:02 angular-robot[bot]

Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Feb 21 '22 15:02 angular-robot[bot]