如何将索引处的行插入已排序的农业网格 [英] How to insert row at index into sorted ag-grid

查看:120
本文介绍了如何将索引处的行插入已排序的农业网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启用排序的网格设置.每行都有一个重复的按钮.复制行时,我想在复制行的下面插入新行.这适用于默认排序方式,但是如果您将其按状态列之类进行排序(例如状态),则会将行随机插入到网格中,因此很难找到它.

I have a grid setup with sorting enabled. Each row has a duplicate button. When duplicating a row, I would like to insert the new row just below the copied row. This works with a default sort but if you sort it on a column like for example status, it randomly inserts the row into the grid, making it hard to find.

我注意到网格在保存期间的某个时候进行了排序,但是还没有得到分配新ID的响应.

I have noticed that the grid does a sort sometime during save, yet before it gets a response to assign a new id.

我尝试使用带有addIndex的updateRowData(transaction)添加行,但是它要么不插入任何内容,要么忽略索引.

I have tried adding the row using updateRowData(transaction) with an addIndex but it either doesn't insert anything or ignores the index.

我确实可以从postSort中访问任何组件变量,但是我只会在postSort之后得到带有ID的响应.

I do have access to any component variables from the postSort but I only get a response with an ID after the postSort.

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");
}

预期:复制的行被插入到原始行的正下方. 实际:将复制的行插入到网格中的某个位置.

Expected: The copied row gets inserted just below the original row. Actual: The copied row get inserted somewhere in the grid.

推荐答案

它将行随机插入到网格中,使其很难找到.

it randomly inserts the row into the grid, making it hard to find.

实际上,它不是随机的,可以通过 updateRowData

Actually it's not random, new values could be inserted via updateRowData

api.updateRowData({add:[listofvalues], addIndex:startIndexPosition})

要插入的对象的listofvalues列表(即使只是一个对象),以及startIndexPosition 索引的位置将从插入位置开始,不进行排序 >

where listofvalues list of objects to insert (even if it would be just one object), and startIndexPosition index of position from where insert will start without sorting

让我们更深入,ag-grid几乎没有状态:

Let's go deeper, the ag-grid has few states:

  1. 默认:它将准确显示它如何传递给rowData,在这种情况下,addIndex很重要,我想只使用默认状态addInex.
  2. 已排序:它将根据排序条件显示.
  3. 已分组:猜测其复杂状态,因为可以将组定义为默认组并进行排序
  1. Default: it would be displayed exactly how it's passed to rowData and on this case addIndex is matter, and I suppose only on default state addInex is used.
  2. Sorted: it would be displayed based on sorting conditions.
  3. Grouped: guess its complex state because groups could be defined as default and has sorting

简单的 示例 进行演示

Simple example for demonstration

尝试按运动员进行排序(更改为asc,desc和默认排序),然后点击添加行,您将在开始,结束和插入位置(默认情况下)看到新行状态)

try to sort (change to sort asc,desc, and default) by athlete and click add row, you will see new rows on start,end and on inserted place (with default state)

这篇关于如何将索引处的行插入已排序的农业网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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