Posted 18 July 2024, 12:56 pm EST - Updated 18 July 2024, 1:02 pm EST
Hi I have problem with ImmutabilityProvider.
First:
example in the Demo doesnt work properly(see the image):
It updates only first typed value. The rest of the flexgrid changes are not represented in the second grid.
And now my implementation:
Stack: I am using redux-toolkit
my state is nested with multiple flexgrids, so
my flexgrid itself looks like
<div className="container-fluid">
<wjcGrid.FlexGrid
itemsSource={viewComponent?.table?.data?.dataSource}
allowMerging="AllHeaders"
headersVisibility={headersVisibility}
>
<ImmutabilityProvider itemsSource={viewComponent?.table?.data?.dataSource} dataChanged={onGridDataChanged}/>
{viewComponent?.table?.data?.dataSource?.length > 0 &&
Object.keys(viewComponent?.table?.data?.dataSource[0])
.filter(key => key.startsWith('col_'))
.map((col, index) => {
const colProps = columnsProps[index];
const dataType = colProps?.dataType;
return (
<wjcGrid.FlexGridColumn
key={index}
binding={`${col}.value`}
header={''}
allowMerging={true}
dataType={dataType}
/>
);
})}
</wjcGrid.FlexGrid>
</div>
onGrid changed
const onGridDataChanged = useEvent((s, e) => {
switch (e.action) {
case wjcGridImmutable.DataChangeAction.Change:{
dispatch(editCell({ newItem: e.newItem || {}, oldItem: e.oldItem, row: e.itemIndex, id: viewComponent.id }));
break;
}
default:
throw 'Unknown data action';
}
});
my reducer:
reducers: {
editCell: (state, action: PayloadAction<{ newItem: {}; oldItem1: {}; row: number; id: string }>) => {
const { newItem, row, id} = action.payload;
const viewComponent = state.viewComponents.find(vc => vc.id === id);
if (viewComponent && isTableViewComponent(viewComponent)) {
const items = viewComponent.table.data.dataSource;
const index = row;
const oldItem = items[index];
const clonedItem = Object.freeze(copyObject({}, oldItem, newItem));
const newDataSource = [
...items.slice(0, index),
clonedItem,
...items.slice(index + 1),
];
const updatedViewComponent = copyObject({}, viewComponent, {
table: copyObject({}, viewComponent.table, {
data: copyObject({}, viewComponent.table.data, {
dataSource: newDataSource
})
})
});
return {
...state,
viewComponents: state.viewComponents.map(vc =>
vc.id=== id ? updatedViewComponent : vc
)
};
}
return state;
},
},
The problem is that most of the time when I am returning new state (95% of the edits) I am getting error
Uncaught Positive number expected. (see the second image)
Not sure whats causing it.
Greetings
