Ag网格检查最后一行是否是新的

时间:2019-12-17 09:46:34

标签: angular ag-grid

我有一个grid,可以通过row创建一个新的updateRowData()。现在,我想做的是通过cellrenderer向新行添加一个链接。
我现在的问题是,有没有办法检查最后创建的行是否是新行?我已经查看了参数,但是似乎找不到能说明该行是否创建的任何内容

下面是我目前正在处理的代码。我通过列定义中的cellRenderer变量来调用它。请查看关于我的问题的代码中的iCreate元素。

`customCellRendererFunc(params: any): any{
    const _this = this;
    const mainDiv = document.createElement('div');

    if(
      Object.entries(params.node.childrenMapped).length === 0 &&
      params.node['field'] !== undefined
    ){ 
      const iEdit = document.createElement('i');
      const iCreate = document.createElement('i');
      const originalLength = params.node.allLeafChildren.length;
      const data = params.node.allLeafChildren[0].data;
      const billingruleID = data.billingruleID;

      iEdit.className = 'fa';
      iEdit.classList.add('fa-edit');
      iEdit.setAttribute('aria-hidden', 'true');
      iEdit.setAttribute('style', 'cursor: pointer; margin-left:10px;');
      iEdit.addEventListener('click', function() { 

      });

      iCreate.className = 'fa';
      iCreate.classList.add('fa-plus-circle');
      iCreate.setAttribute('aria-hidden', 'true');
      iCreate.setAttribute('style', 'cursor: pointer; margin-left:10px;');
      iCreate.addEventListener('click', function() {
        const length = params.node.allLeafChildren.length;

        if(length <= originalLength) {
          const index = length - 1;
          const node = params.node.allLeafChildren[index];
          const newNode = _this.createNewRow(node.data);

          _this.gridApi.updateRowData({ add: [newNode] });
        } else {
          _this.displayDialog("Notice", "Kindly save previous record first 
before creating new one.");
          return false;
        }
      });

      mainDiv.appendChild(iCreate);
      mainDiv.appendChild(iEdit);
    } else if(!params.node.group && params.node.lastChild) {
      const iRemove = document.createElement('i');

      iRemove.className = 'fa';
      iRemove.classList.add('fa-trash');
      iRemove.setAttribute('aria-hidden', 'true');
      iRemove.setAttribute('style', 'cursor: pointer; margin-left:10px;');

      mainDiv.appendChild(iRemove);
    }

    return mainDiv;
  }`

0 个答案:

没有答案