How to insert row at index into sorted ag-grid

后端 未结 2 818
南旧
南旧 2021-01-19 17:49

I have a grid setup with sorting enabled. Each row has a duplicate button. When duplicating a row, I would like to insert the new row just below the copied row. This works w

相关标签:
2条回答
  • 2021-01-19 18:17

    it randomly inserts the row into the grid, making it hard to find.

    Actually it's not random, new values could be inserted via updateRowData

    api.updateRowData({add:[listofvalues], addIndex:startIndexPosition})

    where listofvalues list of objects to insert (even if it would be just one object), and startIndexPosition index of position from where insert will start without sorting

    Let's go deeper, the ag-grid has few states:

    1. Default: it would be displayed exactly how it's passed to rowData and on this case addIndex is matter, and I suppose only on default state addInex is used.
    2. Sorted: it would be displayed based on sorting conditions.
    3. Grouped: guess its complex state because groups could be defined as default and has sorting

    Simple example for demonstration

    try to sort (change to sort asc,desc, and default) by athlete and click add row, you will see new rows on start,end and on inserted place (with default state)

    0 讨论(0)
  • 2021-01-19 18:29

    Apparently, agGrid themselves broke (well, depreciated) the addIndex functionality in agGrid v23.1.... oh, but they then decided to bring it back with v24.1.

    Yes, seriously.

    So, the best way to fix this is to first, check if you have an older version of agGrid:

    npm outdated
    

    And if so, update it using:

    npm install ag-grid-angularlatest
    npm install ag-grid-community@latest
    npm install ag-grid-enterprise@latest
    
    0 讨论(0)
提交回复
热议问题