Comments (7)
I was mutating data like this:
setRowChecked(value, id) {
const data = this.state.data.map((item) => {
if (item.id === id) {
item.checkbox = value;
}
return item;
});
this.setState({
data,
});
}
And I forgot about that item
inside map function has still same reference, so map function creates new array but actual objects inside are not new. return { ...item }
fixes my problem.
Thank you for your help. Nice lib by the way!
from table.
Just create a shallow copy and pass it to Table
after you modify dataSource
。
from table.
I am doing that like: (simplified use case)
import React from 'react';
import RcTable from 'rc-table';
class Table extends React.Component {
constructor(props) {
super(props);
this.state = {
data: props.data,
columns: props.columns,
};
}
render() {
const columns = [...this.state.columns];
const data = [...this.state.data];
return (<RcTable
columns={columns}
data={data}
/>);
}
}
from table.
So, this may work.
from table.
Yeah, but sadly don't. I was suspicious, that data state is mutated somewhere inside Table.jsx
, but I can't find what is wrong.
from table.
There is a tricky problem for array immutable data:
const a = { key: 'value' };
const data = [a];
const newData = [...data];
newData[0].key = 'new value';
console.log(data[0].value); // new value
I made same mistake here: ant-design/ant-design@abecc44
from table.
const a = { key: 'value' };
const data = [a];
const newData = [...data];
newData[0] = { ...data[0] };
console.log(data[0].value); // value
from table.
Related Issues (20)
- antd table,已经设置了 scroll={{x:true}} ,但是有的时候表格显示正常,有的时候内容会撑出去,把整个页面给撑开 HOT 1
- 没有设置 `title` 的列,展示时表头变成了 `td`,应该是 `th` HOT 5
- 【咨询】请问rc-table 虚拟列表支持row动态高度吗
- flex布局时,resize窗口,表格无法自动适应
- Feature Request: Add Hierarchical Lines to Expandable Row RC Table
- 能否提供一个类似elementui table 树形数据与懒加载 的API
- npm run compile error !!! How to build component? HOT 1
- 虚拟滚动时,table getRowKey 索引index 为undefined
- 更复杂的分组表头 HOT 5
- 虚拟滚动时,固定列阴影消失 HOT 2
- VirtualTable 虚拟列表如何处理 load more?
- SSR with Nextjs14+
- Tailwind customization table
- Option to scroll smooth to row in scrollTo function HOT 1
- 虚拟滚动时,当数据源发生变更时,横向滚动被重置
- rc-table show fixed column shadown as expected when viewport zoom in/out with some width
- scroll更新时不能滚动 HOT 1
- fixFooter 判断不准确,导致 Summary 组件的 fixed 为 'top' 不符合预期
- expandedRowRender and colspan
- onScroll 事件的属性 firefox 和 chrome 表现不一致 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from table.