bencripps / react-redux-grid

A React Grid/Tree Component written in the Redux Pattern
http://react-redux-grid.herokuapp.com/
MIT License
447 stars 63 forks source link

EditorActions.addNewRow documentation or sample code #212

Open diego-inflightvr opened 6 years ago

diego-inflightvr commented 6 years ago

Hi Ben,

I'm trying to add a feature that allows the user to create a new child under an specific node (in a tree grid) but I'm not being able to make it. I'm using the following event handler in for the menu action: EVENT_HANDLER: ({ metaData }) => { const rowIndex = metaData.rowIndex + 1 store.dispatch(Actions.EditorActions.addNewRow({ stateKey, rowIndex, columns, data: { id: "666", parentId: metaData.rowData._id, children: [], name: 'some name', description: 'some description' } })); }

This code adds a new row but NOT under the parent node (just adds it below it as a sibling) and most importantly, it throws some errors like this one: image

From debugging I see the problem is that the variable treeData is empty (all its properties are an empty string or null, etc) in the Cell class. In particular, the "depth" prop inside the treeData json is an empty string.

I guess I'm probably doing something wrong in the rest of my code but I couldn't find any example that shows how to add new rows to the grid. If you have any sample code of this I would really appreciate it...

Thanks in advance! Cheers

diego-inflightvr commented 6 years ago

Anyone? I've tried to implement the feature in the tree example grid provided in this repo and I'm facing the same issue...

Phenixer commented 4 years ago

We are facing the same problem. From what I understand, the object in memory has the wrong data format.

We could potentially create our own Action+Reducer and use internals of React-Redux-Grid to build up a new item. I believe the code is not too far from setPartialTreeData in src/reducers/actionHelpers/datasource.js. (which, I think, updates the childrens of a node after a partial load)

Even with that, as soon as I use the inline-editor and save, drag&dropping items in the grid stops working.

The repository hasn't been updated since February, I think I might end up creating my own inline insert state by overriding the row renderer.