this.data.addNew() return null when trying to duplicate row

Posted by: moritz.neugebauer on 23 June 2020, 2:10 am EST

  • Posted 23 June 2020, 2:10 am EST

    Dear Wijmo team,

    I’m using Angular 8 and Wijmo version 5.20193.637.

    When trying to duplicate a row while a cell of that row is selected for editing (double click on cell, then right click on the same cell to open context menu) this.data.addNew() returns null, but the new row is still being created.

    Context Menu

    
    <wj-menu #ctxMenu style="display:none" [header]="'Context Menu'" [selectedValuePath]="'cmd'"
                        [dropDownCssClass]="'ctx-menu'">
                        <wj-menu-item [cmd]="cmdCopy">
                            <span class="glyphicon wj-glyph-file"></span>&nbsp;&nbsp;Zeile kopieren
                        </wj-menu-item>
                    </wj-menu>
    
    

    cmdCopy()

    
    cmdCopy = {
        canExecuteCommand: () => {
          return this.flexdata && this.flexdata.selectedRows && this.flexdata.selectedRows.length > 0 &&
            this.canCreate()
        },
        executeCommand: () => {
          let flexIndex = this.flexdata.selectedRows[0].index;
          let rowsData = this.flexdata.rows[flexIndex].dataItem;
          this.copyIntoNew(rowsData);
        }
      };
    
    
    
    async copyIntoNew(data: any) {
        let newitem = this.data.addNew();
        this.selectedKatalogwert = newitem;
        Object.keys(newitem['attributWerte']).forEach(key => {
          ...
        });
        this.flexdata.select(new CellRange(0, 0, 0, 0));
    
        let newSelectIndex = 0;
        this.flexdata.rows.forEach((r, i) => {
          if (r.dataItem.guid === newitem.guid) {
            newSelectIndex = i;
          }
        });
    
        this.flexdata.select(new CellRange(newSelectIndex, 0));
      }
    
    

    Calling newitem[‘attributWerte’] produces a typescript error.

    Why does this happen?

    Best regards

    Moritz

  • Posted 24 June 2020, 12:47 am EST

    Hi Moritz,

    What error are you getting while using the copyIntoNew method? Are you using newItemCreator property? If you are please make sure that it returns a template of the item along with the ‘attributWerte’ key.

    You will also need to call the commitNew method of CollectionView when you have completed setting the properties of the new item, so that the CollectionView will commit the newly added item.

    Refer to the sample below that demonstrates how to copy a row to a new row:

    https://stackblitz.com/edit/angular-mjzgex

    Regards,

    Ashwin

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels