Trigger selectionChanged after deleting row from gridData

Posted by: moritz.neugebauer on 9 September 2020, 8:44 am EST

    • Post Options:
    • Link

    Posted 9 September 2020, 8:44 am EST

    Dear Wijmo team,

    I’m using Angular to render Flexgrid. I have a variable called selectedItem that I use to display data of a single item from the grid in a detail component next to the grid.

    When deleting a row from the grid, the selectedItem isn’t updated. I wonder why.

    Delete method

    
    async delete(){
        if (this.selectedItem.id){
          let result = await this.api.deleteLi(this.selectedItem.id);
          let rowData = this.data.sourceCollection.find(k=>k.id===this.selectedItem.id);
          this.data.remove(rowData);
        } else if (this.selectedItem.guid){
          let rowData = this.data.sourceCollection.find(k=>k.guid===this.selectedItem.guid);
          this.data.remove(rowData);
        }
        if (this.data.sourceCollection.length===0){
          this.selectedItem={};
        }
        this.data.refresh();
        this.checkChanges();
      }
    
    

    Selection Changed Method

    
    async selectionChanged(e: CellRangeEventArgs) {
        if (this.flexdata.rows[e.range.row]){
          this.selectedItem=this.flexdata.rows[e.range.row].dataItem;
          this.checkChanges();
        }
      }
    
    

    To me it seems that the selectionChanged method isn’t triggered when I delete a row. Is there a way to manually trigger the selectionChanged method?

    Best regards

    Moritz

  • Posted 10 September 2020, 4:01 am EST

    Hi Moritz,

    Your conclusion is correct. The selectionChanged is not fired when an item is deleted because the cell selection is not changed and only the underlying data is updated.

    You can manually trigger the selectionChanged event by calling the onSelectionChanged method:

    var rng = new wjcGrid.CellRangeEventArgs(grid.cells, grid.selection);
    grid.onSelectionChanged(rng);
    

    Regards,

    Ashwin

  • Posted 11 September 2020, 3:04 am EST

    Hi Ashwin,

    thank you for your response. It works as expected. :slight_smile:

    Best regards

    Moritz

Need extra support?

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

Learn More

Forum Channels