Ag-Grid and disabling a button

喜夏-厌秋 提交于 2019-12-11 07:05:02

问题


I want to disable a button as long as any row is not selected in my ag-grid. When a row is selected I want to activate a button. Here my code:

app.component.html

<button disabled="activeButtons">Disable me</button> <!--option 1-->
<button ng-disabled="activeButtons()">Disable me</button> <!--option 2-->

<ag-grid-angular 
     #agGrid
     style="width: 500px; height: 500px;" 
     class="ag-theme-balham"
     [enableSorting]="true"
     [enableFilter]="true"
     [rowData]="rowData | async" 
     [columnDefs]="columnDefs"
     rowSelection="multiple">
</ag-grid-angular>

app.component.ts

getSelectedRows() {
  const selectedNodes = this.agGrid.api.getSelectedNodes();
  return selectedNodes == null;
}

How can I notify from the function getSelectedRows to my template button?


回答1:


app.component.html

<button [disabled]="disableButtons">Disable me</button>

<ag-grid-angular 
     #agGrid
     style="width: 500px; height: 500px;" 
     class="ag-theme-balham"
     [enableSorting]="true"
     [enableFilter]="true"
     [rowData]="rowData | async" 
     [columnDefs]="columnDefs"
     rowSelection="multiple"
     (selectionChanged) = 'onSelectionChanged($event)'>
</ag-grid-angular>

app.component.ts

onSelectionChanged(event: any){
  var selectedRows =  this.agGrid.api.getSelectedRows();
  this.disableButtons = selectedRows.length === 0;
}


来源:https://stackoverflow.com/questions/52654643/ag-grid-and-disabling-a-button

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!