2017-06-20 56 views
0

我正在使用智能表(1)允许用户从不同的页面选择记录,这些记录显示在预览div中。如何使用智能表更改页面后继续选择?

当前的问题是,当我从第一页选择一些记录时,导航到秒,然后导航回到第一页,第一页中的选择内容不反映先前的选择。

当前选择如果保存在名为operatorSelection(2)的映射中,并且我的第一次尝试是在onChangedSource事件(3)后再次选择行,但即使在调用multipleSelectRow()之后,getSelectedRows()也不会返回预期的行。

页面更改后有没有其他的方式来保持选择?或以其他方式从代码中选择行?

下面是代码片段:

(1)成分,它的HTML

<div class="col-lg-6"> <ng2-smart-table #grid [settings]="settings" [source]="source" (userRowSelect)="onUserRowSelect($event)"> </ng2-smart-table> </div>

(2)用于行选择的分量代码

onUserRowSelect(event) { 
console.log('on UserRowSelect', event, this.operatorSelection); 

if (event.isSelected) { 
    this.operatorSelection.set(event.data.code, event.data); 
} else { 
    this.operatorSelection.delete(event.data.code); 
} 

this.updatePreview(); 
} 

(3)什么我试图在更改页面后更新选择

ngAfterViewInit(): void { 
this.table.grid.source.onChangedSource.subscribe(() => { 
    this.operatorSelection.forEach((row) => { 

    this.table.grid.source.data.forEach((element) => { 
     if (element.code == row.code) { 
     console.log('--- reselect ', row.code); 
     this.table.grid.multipleSelectRow(row); 
     console.log('*** selected ', this.table.grid.getSelectedRows()); 
     } 
    }); 
    }); 
}); 
} 

回答

0

Angular在遍历组件时使用本地存储来存储数据,通过上面提到的数据源刷新onInit组件。

您必须使用服务来存储您希望保留的数据,同时通过组件的onInit遍历并将此数据设置为数据源。

相关问题