Ag-Grid并禁用按钮

时间:2018-10-04 20:25:24

标签: angular ag-grid

我想禁用一个按钮,只要在我的农业网格中未选择任何行即可。选择一行后,我想激活一个按钮。这是我的代码:

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;
}

如何从getSelectedRows函数通知我的模板按钮?

1 个答案:

答案 0 :(得分:0)

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;
}