app.component.html
<div class="inlineBlock">
<select [(ngModel)]="portId" id="portDropdownMenu" (change)="externalFilterChanged()">
<option *ngFor="#portId of portIds">{{portId}}</option>
</select>
</div>
<div class="container">
<ag-grid-ng2 #agGrid
[gridOptions]="gridOptions"
[columnDefs]="myColumnDefs"
[rowData]="myRowData"
enableColResize
rowSelection="multiple"
enableSorting
enableFilter
[isExternalFilterPresent]="isExternalFilterPresent"
[doesExternalFilterPass]="doesExternalFilterPass"
rowHeight="30"
headerHeight="40"
enableRangeSelection
suppressContextMenu
suppressMenuColumnPanel
rowGroupPanelShow="always"
rememberGroupStateWhenNextData
groupDefaultExpanded="-1"
groupHideGroupColumns
groupUseEntireRow
(modelUpdated)="onModelUpdated()"
(filterChanged)="onFilterChanged()">
</ag-grid-ng2>
</div>
app.component.ts
public isExternalFilterPresent() {
return this.portType != "All Ports";
}
public doesExternalFilterPass(node) {
switch (this.portType) {
case "1": return node.data.Port === "1";
case "2": return node.data.Port === "2";
case "3": return node.data.Port === "3";
default: return true;
}
}
public externalFilterChanged() {
var newValue = (<HTMLInputElement>document.getElementById("portDropdownMenu")).value
this.portType = newValue;
this.gridOptions.api.onFilterChanged();
}
public onFilterChanged() {
if (this.gridOptions.api.isAnyFilterPresent()) {
this.gridOptions.api.setRowData(this.gridOptions.rowData);
this.gridOptions.api.refreshView();
}
console.log("filter changed ...");
}
By console.log(this.gridOption.isAnyFilterPresented()), I notice the filter does exist when dropdown menu is updated. However, the grid is not updating according to external filter.
I am pretty sure "isExternalFilterPresent()" and "doesExternalFilterPass(node)" run through and provides the correct return value. My understanding is that ag-grid will take care of the rest but it is not doing it. Any idea?
there is a solution to this issue.
declare the two functions: isExternalFilterPresent,doesExternalFilterPass in type script,
get an instance of the gridOptions,
private gridOptions:GridOptions;
and in the constructor:
this.gridOptions = <GridOptions>{};
then
this.gridOptions.isExternalFilterPresent = this.isExternalFilterPresent.bind(this);
this.gridOptions.doesExternalFilterPass = this.doesExternalFilterPass.bind(this);
now, you will be able to access the component's variables inside those functions:
this.myVariable
full description the problem+solution: https://github.com/ceolter/ag-grid-ng2/issues/121
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With