How to programmatically trigger refresh primeNG datatable when a button is clicked

前端 未结 3 1176
情歌与酒
情歌与酒 2021-01-12 00:54

I have a refresh button that is outside the primeNG datatable. How do I programmatically trigger to refresh the datatable?

something like this:



        
3条回答
  •  心在旅途
    2021-01-12 01:13

    If you refresh the list in the component, the table refresh automatically. Example after confirm a delete operation:

    import { Component } from '@angular/core';
    import { Interface } from '../..//model/interface.model'
    import { InterfaceService } from '../../service/interface.service'
    import { ButtonModule } from 'primeng/primeng';
    import { ConfirmDialogModule, ConfirmationService } from 'primeng/primeng';
    
    @Component({
        templateUrl: './interfaces.component.html'
    })
    export class InterfacesComponent {
    
        interfaces: Interface[];
    
        constructor(
            private interfaceService: InterfaceService,
            private confirmationService: ConfirmationService
        ) { }
    
        ngOnInit() {
            this.find();
        }
    
        find() {
            this.interfaceService.query().then(interfaces => this.interfaces = interfaces);
        }
    
        confirm(id: number) {
            this.confirmationService.confirm({
                message: 'Are you sure that you want to delete this record?',
                accept: () => {
                    this.interfaceService.delete(id).then((_interface) => {
                        this.find();
                    });            
                }
            });
        }
    
    }
    

提交回复
热议问题