问题
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