Coder Social home page Coder Social logo

Comments (8)

liuy97 avatar liuy97 commented on July 28, 2024

Have you tried demo-project or demo-ng8?

from mat-vs-table.

bubooon avatar bubooon commented on July 28, 2024

Yes, I saw demo-ng8 source code.

from mat-vs-table.

bubooon avatar bubooon commented on July 28, 2024

So, I realized what a problem. If you will recreate dataSource during the app lifecycle (for example after a state of data items will change) you will have this error.
Example of code:

ngOnInit(){
  this.someObservable.subscribe(users => {
    this.dataSource = new MatTableDataSource<User>(users);
  });
}

In that case on second value from Observable you will get error.

from mat-vs-table.

ForTimeBeing avatar ForTimeBeing commented on July 28, 2024

So, I realized what a problem. If you will recreate dataSource during the app lifecycle (for example after a state of data items will change) you will have this error.
Example of code:

ngOnInit(){
  this.someObservable.subscribe(users => {
    this.dataSource = new MatTableDataSource<User>(users);
  });
}

In that case on second value from Observable you will get error.

Thanks for pointing out the problem, but what if I have to recreate the datasource because of sorting? Am I unable to use this?

EDIT: The reason why mine was causing this, was because I was initilizing dataSource above(in the class) such as;

dataSource = new MatTableDataSource([]);

Then in the actual code function I recreated dataSource (since I am PULLING in the data and it is UNKNOWN during startup) Nearly every example ive seen is with known data. Anyways in the function I had
this.dataSource = new MatTableDataSource(tableArr);

from mat-vs-table.

liuy97 avatar liuy97 commented on July 28, 2024

I guess you can do the following instead of creating new MatTableDataSource each time
this.dataSource.data = users

You assign new data after you do searching.

from mat-vs-table.

ForTimeBeing avatar ForTimeBeing commented on July 28, 2024

I guess you can do the following instead of creating new MatTableDataSource each time
this.dataSource.data = users

You assign new data after you do searching.

I'm not sure if you're replying to my post, but I try not to change the data of the data source such as datasource.data . I use filtering and when changing the data, it won't filter correctly if I change the data. I would have to reload the datasource hurting performance

Edit: either way my problem is solved. It's working Amazingly. I'm having issues with sorting / resizing now. When resizing, it will also sort the column you release your mouse at while resizing.

from mat-vs-table.

liuy97 avatar liuy97 commented on July 28, 2024

Good to know the problem gets resolved. If you can provide demo in stackblitz, I can maybe help you.

from mat-vs-table.

ForTimeBeing avatar ForTimeBeing commented on July 28, 2024

Good to know the problem gets resolved. If you can provide demo in stackblitz, I can maybe help you.

It's 2:30am right now and I'm in bed but maybe tomorrow I'll see if I can set it up. I never used stack blitz but I'll check it out. Basically what is happening is that when you resize you click and hold your mouse, and if you let go in another cell, due to having matsort it also sorts at the same time. I tried adding a check to see if resizing but it isn't working correctly (to disable and enable sorting). Not only that, when resizing with a lot of elements it's very laggy. I was hoping adding this would help. It did help with scrolling A Lot but not resizing. Thanks for the help though! We're getting a bit off subject so please add me and DM me if you can. I appreciate the help again!

from mat-vs-table.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.