2017-04-18 29 views
0

我只需要window.location.reload()僅適用於特定元素。 具體來說,我有一個很多列的表。angular 2重新加載特定html元素

<p-dataTable #tableRef class="invoice-datatable"></p-dataTable>

當我點擊下面的圖片,我稱之爲refreshTable方法,我需要它來只刷新數據表。

`<img role="button" id="refresh-icon" src="/assets/img/refresh.png (click)="refreshTable(tableRef)"> 
+0

如果你使用類似於''的方式將模型綁定到表上,那麼當模型更改時表不會刷新? –

+0

它確實如此。但是如何通過點擊圖像來實現這一點? –

回答

0

有到DataTable重置爲

export class MyComponent implements OnInit { 
    @ViewChild(DataTable) dataTableComponent: DataTable; 

    // ... 

    refreshTable() { 
     this.dataTableComponent.reset(); 
    } 
} 
0

如果你的數據表上綁定到一個模型的一些方法,那麼你只需要點擊圖像時更新與任何必要的新的數據模型。使用.reset()只會重置過濾器,排序和分頁。不幸的是,它並沒有刷新數據。