我已经进行了serverSide
分页和过滤,但是随着分页的进行,过滤无法正常工作。触发过滤器操作后,将过滤响应,但是过滤器值本身消失了-这是网格的正常行为吗?我看到文档示例保存了过滤器输入值,我的问题已清除。
items: Item[] = [];
gridOptions: GridOptions = {
pagination: true,
rowModelType: 'serverSide',
cacheBlockSize: this.itemsPerPage,
paginationPageSize: this.itemsPerPage
};
columnDefs: ColDef[] = [
{
field: 'name',
filter: 'agTextColumnFilter',
filterParams: {
},
sortable: true
},
{
field: 'value',
filter: 'agTextColumnFilter',
sortable: true
},
{
field: 'Actions',
cellRendererFramework: ItemActionRendererComponent,
cellRendererParams: {
label: 'actions'
}
},
{ field: 'hiddenColumn', filter: 'agTextColumnFilter', sortable: true, hide: true }
];
// ...
onGridReady = params => {
this.gridApi = params.api;
this.columnApi = params.columnApi;
this.gridApi.refreshHeader();
this.gridApi.setServerSideDatasource(this.gridServerDataSource());
};
gridServerDataSource(): IServerSideDatasource {
return {
getRows: (params: IServerSideGetRowsParams) => {
const request: IServerSideGetRowsRequest = params.request;
this.itemService
.query({
page: request.endRow / this.itemsPerPage - 1,
size: this.itemsPerPage,
sort: this.sort(request.sortModel),
filter: this.filter(request.filterModel)
})
.subscribe(
(res: HttpResponse<IOrder[]>) => this.paginateItems(res.body, res.headers, params),
(res: HttpErrorResponse) => this.onError(res.message)
);
}
};
}
protected paginateItems(data: IOrder[], headers: HttpHeaders, params: IServerSideGetRowsParams) {
this.links = this.parseLinks.parse(headers.get('link'));
this.totalItems = parseInt(headers.get('X-Total-Count'), 10);
params.successCallback(data, this.totalItems);
}
<ag-grid-angular
[gridOptions]="gridOptions"
[rowData]="items"
[columnDefs]="columnDefs"
[floatingFilter]="true"
[sideBar]="sideBar"
(gridReady)="onGridReady($event)"
[frameworkComponents]="frameworkComponents">
</ag-grid-angular>
我的设置有问题吗?