【发布时间】:2019-08-17 05:48:40
【问题描述】:
我有一个启用排序的网格设置。每行都有一个重复按钮。复制一行时,我想在复制行的下方插入新行。这适用于默认排序,但如果您对列进行排序,例如状态,它会随机将行插入网格,使其难以找到。
我注意到网格在保存期间的某个时间进行了排序,但在它收到分配新 ID 的响应之前。
我尝试使用带有 addIndex 的 updateRowData(transaction) 添加行,但它要么不插入任何内容,要么忽略索引。
我确实可以从 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");
}
预期:复制的行被插入到原始行的正下方。 实际:复制的行被插入到网格中的某处。
【问题讨论】: