簡體   English   中英

如何在墊表 angular 材料中排序時顯示確認

[英]how to show confirm when sort in mat-table angular material

我正在使用 angular 8 和 angular 材料 8,我想在墊表上排序時顯示確認。 如果用戶確認真圖標會改變,當確認假假圖標不會改變。 我該怎么做?? 請幫助解決此問題stack-blitz 鏈接

如果我理解正確,您的要求是要求用戶在調用 function 對數據進行排序之前確認排序。

如果是這樣,您有兩個選擇:

  • 創建一個自定義指令來“手動”處理排序;
  • 如果用戶取消它,則將最后一個排序事件保存到可能的“回滾”操作。

這是第二個的例子。 方法:

@Component({
  // ...
})
export class TableSortingExample {
  @ViewChild(MatSort, { static: true }) sort: MatSort;
  lastSort: Partial<Sort> = {};

  sortChangeHandler(evt: Sort): void {
    if (confirm('Confirm question?')) {
      this.lastSort = {
        active: this.sort.active,
        direction: this.sort.direction
      };
      // Perform sort operation
    } else {
      this.sort.active = this.lastSort.active;
      this.sort.direction = this.lastSort.direction;
    }
  }
}

完整演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM