我在这里使用了一些示例(https://github.com/primefaces/primeng/issues/304),以便将排序和页面保留在本地存储中,以便当用户返回页面时,他们的设置是保持。
但是,我无法保存过滤器,并且找不到任何示例。
模板:
<p-dataTable #dt [value]="FilteredIncidentNodes" [rows]="10" [paginator]="true" [pageLinks]="10" [rowsPerPageOptions]="[5,10,20]" [editable]="true"
(onPage)="onPage($event)" (onSort)="onSort($event)" (onFilter)="onFilter($event)">
代码:
onFilter(e) {
localStorage.setItem("filters", JSON.stringify(e));
}
ngOnInit() {
const opt = localStorage.getItem(this.optionsKey);
const filters = localStorage.getItem("filters");
if (opt) {
let go = JSON.parse(opt);
setTimeout(() => {
this.gridOptions = go;
this.dataTable.sortField = this.gridOptions.sortField;
this.dataTable.sortOrder = this.gridOptions.sortOrder;
this.dataTable.sortSingle();
this.dataTable.paginate(this.gridOptions);
if (filters) {
console.log(JSON.parse(filters));
this.dataTable.filters = JSON.parse(filters);
}
//this.blocked = false;
}, 0);
return;
}
}