переменная row является глобальной переменной в вашем файле. Через 5 секунд переменная строки изменилась, но, поскольку переменная строки не поддерживается ни состоянием компонента примера, ни опорой для компонента примера, изменение не отслеживается методами жизненного цикла компонента примера. Поэтому метод рендеринга компонента Example не вызывается, когда изменяется переменная row, и поэтому ReactDataGrid не получает обновленные значения.
попробуйте сохранить переменную rows в состоянии компонента Example. как это-
let cols = [
{
key: 'sapAssetNumber',
name: 'SAP Asset number',
editable: false
},
{
key: 'assetDescription',
name: 'Description',
editable: false
},
{
key: 'assetNBV',
name: 'Asset NBV',
editable: false
},
{
key: 'salePrice',
name: 'Sale price',
editable: false
}
];
let rows = [
{
"id" : "0",
"sapAssetNumber" : "woof",
"isAlreadyDisposed" : "",
"assetDescription" : "test",
"assetNBV" : "100",
"salePrice" : "100"
},
{
"id" : "0",
"sapAssetNumber" : "",
"isAlreadyDisposed" : "",
"assetDescription" : "test",
"assetNBV" : "100",
"salePrice" : "100"
},
{
"id" : "this",
"sapAssetNumber" : "is",
"isAlreadyDisposed" : "a",
"assetDescription" : "test",
"assetNBV" : "",
"salePrice" : ""
},
{
"id" : "jfkhkdafhn",
"sapAssetNumber" : "",
"isAlreadyDisposed" : "",
"assetDescription" : "",
"assetNBV" : "",
"salePrice" : ""
},
{
"id" : "kjdsaflkadjsf",
"sapAssetNumber" : "",
"isAlreadyDisposed" : "",
"assetDescription" : "",
"assetNBV" : "",
"salePrice" : ""
},
{
"id" : "",
"sapAssetNumber" : "",
"isAlreadyDisposed" : "",
"assetDescription" : "",
"assetNBV" : "500",
"salePrice" : "500"
}
];
class Example extends React.Component {
constructor() {
super();
this.state={rows:rows}
}
componentDidMount = () =>{
const context = this;
setTimeout(() => {
rows[0].sapAssetNumber = 'meow'
context.setState({rows});
}, 5000);
}
render() {
return <ReactDataGrid
columns={cols}
rowGetter={(i) => rows[i]}
rowsCount={10}
/>;
}
}
ReactDOM.render(<Example />, document.querySelector("#app"));
пожалуйста, прочтите это для ясности состояния компонента: - https://reactjs.org/docs/faq-state.html
Прочтите это, чтобы узнать, когда вызывается метод рендеринга: - https://lucybain.com/blog/2017/react-js-when-to-rerender/
Надеюсь, это решит проблему!