我有一个启用排序的网格设置。每行都有一个重复按钮。复制行时,我想在复制的行下方插入新行。这适用于默认排序,但如果您对列进行排序(例如状态),它会将该行随机插入到网格中,从而很难找到。
我注意到网格在保存过程中的某个时候会进行排序,但在它得到分配新 ID 的响应之前。
我尝试使用 updateRowData(transaction) 和 addIndex 添加行,但它要么不插入任何内容,要么忽略索引。
我确实可以访问 postSort 中的任何组件变量,但在 postSort 后我只能收到带有 ID 的响应。
cloneRow(item: any): void {
let newRow = JSON.parse(JSON.stringify(item.data)) as Object;
newRow.gridItemId = null;
this.index = this.api.getFocusedCell().rowIndex;
this.selectRow(newRow, ++index);
this.saveRow(newRow);
}
selectRow(newRow: Object, index: number) {
this.selectedObject = [];
this.gridItemList.splice(index, 0, newRow);
this.api.setFocusedCell(index, "ColumnName");
this.api.startEditingCell({
rowIndex: index,
colKey: "ColumnName"
});
}
saveRow(newRow: Object): void {
let objectsToSave = new Array<Object>();
objectsToSave.push(newRow);
this.CustomService.saveRow(objectsToSave)
.subscribe(
(response) => {
if (!newRow.rowId) {
newRow.rowId = response[0].rowId;
}
this.gridItemList.filter(g => g.gridItemId === response[0].gridItemId)[0] = response[0];
this.api.refreshCells();
}
postSort = function(rowNodes) {
console.log("Post Sort");
}
Run Code Online (Sandbox Code Playgroud)
预期:复制的行将插入到原始行的正下方。实际:复制的行被插入到网格中的某个位置。
它将行随机插入到网格中,使其很难找到。
实际上它不是随机的,可以通过插入新值updateRowData
api.updateRowData({add:[listofvalues], addIndex:startIndexPosition})
其中要listofvalues插入的对象列表(即使它只是一个对象),以及插入开始位置的startIndexPosition 索引(无需排序)
让我们更深入地了解一下,ag-grid 有几个状态:
rowData在这种情况下addIndex很重要,我想仅在默认状态下addInex使用。简单example演示
尝试按运动员排序(更改为升序、降序和默认排序)并单击添加行,您将在开始、结束和插入位置看到新行(默认状态)
| 归档时间: |
|
| 查看次数: |
8168 次 |
| 最近记录: |