【问题标题】:Performance of mat-table with 30 000 rows具有 30 000 行的 mat-table 的性能
【发布时间】:2019-04-26 22:11:04
【问题描述】:

我使用 Angular 6、Firebase 和 Angular Material。

我有 30,000 个 json 对象存储在 firebase 中,我想将它们加载到 mat-table 中。只有我比我希望的要低得多。我等了 30 秒才可以点击我的应用程序,有时 chrome 会出错...

但是我在分页后加载了我的数据。

谁能告诉我这是正常的还是有解决这个问题的策略?谢谢。

也许我可以用 Angular 7 和无限滚动来做到这一点?请问有例子吗?

export class TableComponent implements OnInit {

    showSpinner = true;

    Data = {nom: '', finessgeo: '', cat1: '', commune: '', CP: '', departement: '', tel: ''}

    displayedColumns = ['nom', 'finessgeo', 'cat1', 'commune', 'CP', 'departement', 'tel'];

    dataSource = new MatTableDataSource();

    applyFilter(filterValue: string) {
        filterValue = filterValue.trim();
        filterValue = filterValue.toLowerCase();
        this.dataSource.filter = filterValue;
    }

    @ViewChild(MatPaginator) paginator: MatPaginator;

    @ViewChild(MatSort) sort: MatSort;

    ngAfterViewInit() {
        this.dataSource.paginator = this.paginator;
        this.dataSource.sort = this.sort;
        return this.geoService.getGeos().subscribe(res => {
            this.dataSource.data =
                res;
            this.showSpinner = false;
        });
    }

    constructor(public authService: AuthService, private geoService:
        GeoService, private router: Router, private database: AngularFireDatabase) {
    }

    ngOnInit() {}
}

【问题讨论】:

    标签: angular performance firebase angular-material mat-table


    【解决方案1】:

    我有一些建议。

    首先:不要将所有 30k 行加载到客户端。尝试使用服务器端分页。这应该可以解决所有问题。 您还必须在 api 上实现所有过滤和排序功能。使用客户端只是为了显示该数据。

    如果这不是一个选项:

    • 对服务器上的数据进行排序。尽早。如果可以,直接在数据库查询中。
    • 检查您的组件是否将所有行添加到 DOM。这将占用大量 CPU 时间。
    • 使用 chrome 开发工具中的性能选项卡来检查需要这么长时间的原因。并尝试对其进行优化。
    • 检查您的 html 模板。尝试使行尽可能简单。比如嵌套更少的元素、额外的类等等。

    【讨论】:

    • 感谢您的帮助。你有使用 angularfire 和 mattable 的服务器端分页示例吗?
    • 我之前没有使用过firebase,但是每个api的原理都是一样的。找到了这个video,乍一看还不错。
    • 要使用正确的值填充分页器,请查看documentation
    • 你能告诉我更多吗?
    • 如果您有具体问题,也许可以。
    猜你喜欢
    • 2020-01-25
    • 1970-01-01
    • 2019-01-26
    • 2019-10-14
    • 1970-01-01
    • 2020-02-01
    • 2019-11-04
    • 2019-08-31
    • 1970-01-01
    相关资源
    最近更新 更多