ag-grid angular 我想在同一网格内复制选定的行数据,即我想在同一网格中单击按钮时复制并粘贴选定的行
ag-grid angualr i want duplicate the selected row data inside same grid i.e i want copy and pate selected row on button click in the same grid
在 Ag-grid angular 中,我有按钮克隆行,我将 select 网格内的一行并单击克隆行它应该在指定索引中再次创建相同的行,我是能够使用以下代码实现此目的
在 app.ts::
克隆行(){
var selectedRowsIndex = this.gridOptions.api.getSelectedNodes();
var index = selectedRowsIndex[0].rowIndex
var selectedRows = this.gridOptions.api.getSelectedRows();
const temp = [...selectedRows]
for (var i = 0; i < selectedRows.length; i++) {
temp[i].B_CLONE = true;
temp[i].SNO = 3;
}
this.gridOptions.api.insertItemsAtIndex(++index,temp)
}
<button class="btn btn-info ml-3" (click)="cloneRow()">Clone Row</button>
<button class="btn btn-info ml-3" (click)="cloneRow()">Clone Row</button>
我面临的问题是,克隆一行后 (insertItemsAtIndex)
如果添加任何值,现有行也会被新的克隆行更改,即 s.no in gird
如果我编辑重复的 2 行中的任何一行,并更改行中任何一个单元格中的任何值,则两行都会更改。
我想要两行独立于它们的值
为了便于理解,我附上了简称。
original grid before clone
grid after clone
grid after clone changing cell value in one row
您需要深度克隆并分配 temp
对象,如下所示:
this.gridOptions.api.insertItemsAtIndex(++index,Object.assign({}, temp));
相反 Object.assign({}, temp)
您也可以像这样克隆对象(老派的克隆方式):
this.gridOptions.api.insertItemsAtIndex(++index,JSON.parse(JSON.stringify(temp)));
在 Ag-grid angular 中,我有按钮克隆行,我将 select 网格内的一行并单击克隆行它应该在指定索引中再次创建相同的行,我是能够使用以下代码实现此目的
在 app.ts::
克隆行(){
var selectedRowsIndex = this.gridOptions.api.getSelectedNodes();
var index = selectedRowsIndex[0].rowIndex
var selectedRows = this.gridOptions.api.getSelectedRows();
const temp = [...selectedRows]
for (var i = 0; i < selectedRows.length; i++) {
temp[i].B_CLONE = true;
temp[i].SNO = 3;
}
this.gridOptions.api.insertItemsAtIndex(++index,temp)
}
<button class="btn btn-info ml-3" (click)="cloneRow()">Clone Row</button>
<button class="btn btn-info ml-3" (click)="cloneRow()">Clone Row</button>
我面临的问题是,克隆一行后 (insertItemsAtIndex)
如果添加任何值,现有行也会被新的克隆行更改,即 s.no in gird
如果我编辑重复的 2 行中的任何一行,并更改行中任何一个单元格中的任何值,则两行都会更改。
我想要两行独立于它们的值
为了便于理解,我附上了简称。
original grid before clone
grid after clone
grid after clone changing cell value in one row
您需要深度克隆并分配 temp
对象,如下所示:
this.gridOptions.api.insertItemsAtIndex(++index,Object.assign({}, temp));
相反 Object.assign({}, temp)
您也可以像这样克隆对象(老派的克隆方式):
this.gridOptions.api.insertItemsAtIndex(++index,JSON.parse(JSON.stringify(temp)));