AG Grid使用applyTransaction插入行 [英] AG Grid inserting rows with applyTransaction

查看:281
本文介绍了AG Grid使用applyTransaction插入行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在特定索引处而不是在网格末尾插入行?

Is there a way to insert rows at a specific index rather than at the end of the grid?

例如,如果我想从顶部插入10行,该怎么办?还是在中间?

Example would if I want to insert a row 10 rows from the top? Or in the middle?

我确实找到了一种叫做insertItemAtIndex(index, [rows]);

I did find an old ag grid method called insertItemAtIndex(index, [rows]);

,但此方法无效,并表示已弃用.有没有办法用applyTransaction(transaction)做到这一点?

but this isn't working and says it's deprecated. Is there a way to do this with applyTransaction(transaction)?

推荐答案

RowDataTransaction接口具有可选的addIndex属性-

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.

用法:this.gridApi.applyTransaction({ add: newItems, addIndex: 2});

它表示将从中插入新行的索引.

我已经尝试过使用

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)

这篇关于AG Grid使用applyTransaction插入行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆