angular - 新数据清除选择
问题描述
我@swimlane/ngx-datatable
用来显示来自服务器的数据。我轮询这些数据,所以每 1 分钟一次。我得到了一组新数据。我的问题是,如果用户在轮询后选择数据表中的一行,则数据会被新数据重写并且选择会丢失。为了演示它,我在stackblitz创建了一个虚拟示例。
- 等到数据显示在表格中
- 选择一行
- 等到新数据到来(4s,setInterval)
- 选择被清除
知道如何解决这个问题吗?
app.component.ts
import { Component, VERSION, OnInit } from "@angular/core";
import { ColumnMode, SelectionType } from "@swimlane/ngx-datatable";
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent implements OnInit {
SelectionType = SelectionType;
rows = [];
columns = [{ prop: "name" }, { name: "Gender" }, { name: "Company" }];
selected = [];
onSelect({ selected }) {}
ngOnInit() {
setInterval(() => {
this.rows = [
{ name: "Austin", gender: "Male", company: "Swimlane" },
{ name: "Dany", gender: "Male", company: "KFC" },
{ name: "Molly", gender: "Female", company: "Burger King" }
];
}, 4000);
}
}
app.component.html
<div>
<ngx-datatable class="material" [rows]="rows" [columns]="columns" [selected]="selected"
[selectionType]="SelectionType.single" (select)="onSelect($event)">
</ngx-datatable>
</div>
解决方案
推荐阅读
- javascript - 无法从 Web 服务返回的二进制字符串下载 pdf
- javascript - 如何将州名转换为其缩写?
- reactjs - 使用拦截器时无法用axios发送表单数据
- html - 使用 Angular CDK 拖放和 CDKDropListEnterPredicate 交换列表中的元素
- matlab - 如何找出一个范围内的多数点位于 MATLAB 中另一个向量中值的左侧、右侧或中心区域?
- php - 如何添加当前日期是否在某个日期条件之前作为 if 语句参数
- android - 如何在具有多个应用程序模块的项目上使用 Here Maps?
- laravel - 使用 API 中的数据填充 Quasar Tree - 发送处理函数时遇到问题
- revit-api - Revit API:维护多个 API 版本的代码
- javascript - 使用递归