更新数据源时选择列表变为空 - 数据表材料 2 [英] selection list become empty when datasource is updated - datatable materil2

查看:25
本文介绍了更新数据源时选择列表变为空 - 数据表材料 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新数据源时选择列表变为空.

Selection list becomes empty when datasource is updated.

步骤:1.选择一些用户

steps: 1. select some users

步骤:2.选择第二个标签

steps: 2. select second tab

步骤:3.回到第一个标签

steps: 3. come back to the first tab

选择的用户在芯片中可用,但未在数据表中选择.

selected users are available in chips but not selected in datatable.

查看https://stackblitz.com/edit/angular-v3kjgj?embed=1&file=app/selectusers.component.ts

推荐答案

您正在通过行"对象本身保存选择状态,当您更改选择第一个选项卡时,您的 loadUsers() 调用会更改这些状态​​.每次单击第一个选项卡时不要调用 loadUsers()(如果需要刷新数据,请创建一个updateUsers()"方法来保留现有用户对象),或者更改保存选择状态的方式(例如通过行.id).

You are saving selection status by the "row" object itself, which are all changed by your loadUsers() call when you change select the first tab. Either don't call loadUsers() every time you click on the first tab (if you need to refresh data, create an "updateUsers()" method that keeps the existing user objects), or change how you save selection status (e.g. by row.id).

这篇关于更新数据源时选择列表变为空 - 数据表材料 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆