问题
Is there a way to insert rows at a specific index rather than at the end of the grid?
Example would if I want to insert a row 10 rows from the top? Or in the middle?
I did find an old ag grid method called insertItemAtIndex(index, [rows]);
but this isn't working and says it's deprecated. Is there a way to do this with applyTransaction(transaction)
?
回答1:
The RowDataTransaction
interface has an optional addIndex
property -
export interface RowDataTransaction {
/** deprecated */ addIndex?: number;
add?: any[];
remove?: any[];
update?: any[];
}
Although it is marked deprecated, it is working for me.
Usage : this.gridApi.applyTransaction({ add: newItems, addIndex: 2});
It denotes the index from which new rows will be inserted.
I have tried playing around on this example from docs and is working fine.
A related question for old way of updating rows. (without transaction)
来源:https://stackoverflow.com/questions/62238792/ag-grid-inserting-rows-with-applytransaction