updating grid cell via code

Posted by: nirwei on 26 November 2020, 3:51 am EST

  • Posted 26 November 2020, 3:51 am EST

    Hi,

    I'm using flexGrid 5.20203.748 on angular 9.

    some user actions on the grid trigger functions that update multiple cells on the grid.
    the way the updating is done is by accessing the dataItem property on a grid row, addressing a specific key, and updating its value.

    here's an example of multiplying all values in a specific column by 2:


    for(let i=1; I<flexGrid.rows.length;i++){
    const dataItem = flexGrid.rows[i] .dataItem;
    dataItem["QTY"]= dataItem["QTY"]*2;
    }


    on the previous flexgrid version, the grid would display the updated value after the function would complete, but in the current version the grid doesn't reflect the changes, and the cells keep their previous values.

    what am I missing here?

    thanks,
    Nir
  • Replied 26 November 2020, 8:51 pm EST

    Hi Nir,

    You will need to refresh the collectionView of the grid after updating the dataItem:
    for(let i=1; I<flexGrid.rows.length;i++){
    const dataItem = flexGrid.rows[i] .dataItem;
    dataItem["QTY"]= dataItem["QTY"]*2;
    }
    flexGrid.collectionView.refresh():

    There is no change in the 748 version, the refresh method is needed for previous versions also. So, if it was working previously, it may be an issue in the grid itself.

    Regards,
    Ashwin
  • Marked as Answer

    Replied 28 November 2020, 11:03 pm EST

    Thanks Ashwin.
    using
    flexGrid.collectionView.refresh():
    had indeed fixed the problem of the cell value, but it had caused the grid to lose its current location and filtering due to the fact that I'm using a 3 levels nested data model.
    however, using
     flexGrid.invalidate(true);
    updated the cell value and kept the location and filtering.

    Nir
Need extra support?

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

Learn More

Forum Channels