FlexGrid ImmutabilityProvider nested object mutation

Posted by: vladyslav.marsikov on 6 May 2020, 1:20 pm EST

  • Posted 6 May 2020, 1:20 pm EST

    Hi,

    I’m investigating data immutability feature of FlexGrid (with React) and found that for simple flat items like

    
    let data = [{id: 1, downloads: 23}];
    
    

    it works really well.

    But when I tried to use more complex data with nested objects like

    
    let data = [{ item: { id: 1, downloads: 23 }}];
    
    

    FlexGrid performs source data mutation.

    To reproduce this issue slightly modified EditableReduxGrid example (https://www.grapecity.com/wijmo/demos/Grid/Data-binding/ImmutableData/Redux/EditableReduxGrid/react/material).

    All is need is to change data structure in data.jsx:

    
    // add the item to the list
    - data.push(item);
    + data.push({ item });
    
    

    And data binding in GridView.jsx:

    
    - <wjFlexGrid.FlexGridColumn binding="id" header="ID" width={80} isReadOnly={true}></wjFlexGrid.FlexGridColumn>
    + <wjFlexGrid.FlexGridColumn binding="item.id" header="ID" width={80} isReadOnly={true}></wjFlexGrid.FlexGridColumn>
    ...and so on for all columns
    
    

    Is it possible to disable data mutation for such cases?

  • Posted 7 May 2020, 4:56 am EST

    Hi Vladyslav,

    We have forwarded this issue to the developers with internal tracking id 434440. We will update you once we will hear from them.

    Regards,

    Ashwin

  • Posted 8 May 2020, 4:04 am EST

    Hi Vladislav

    Thanks for pointing out this problem. Support for bindings to nested properties was added to ImmutabilityProvider in the latest nightly build. You can check it using the attached sample.

    Note that to allow grid to correctly add new items, you need to provide immutabilityProviedr.collectionView.newItemCreator function implementation, which may look like here:

    () => { return { itm: {} } }

    If to not add the nested object to the new item, the grid will not able to fill it in with the property values typed by a user.

    In addition to the nested bindings support, we also added the cloningItem event into the ImmutabilityProvider class. This event allows you to implement a custom logic for cloning items that are about to be edit by the grid.

    Thanks,

    Alexsample-update.zip

  • Posted 13 May 2020, 10:13 am EST

    Thank you. Now it works.

  • Posted 13 May 2020, 10:58 am EST

    Thanks for checking this. The next hotfix release build, which will include this update, is scheduled for next week.

    Please let us know in case of any additional questions that may arise.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels