Skip to content

Infragistics Community Forum / Web / Ignite UI for Angular / Cannot invoke an object which is possibly 'undefined' on row.delete()

Cannot invoke an object which is possibly 'undefined' on row.delete()

New Discussion
Jose Briz
Jose Briz asked on Dec 14, 2022 2:33 PM

Hi,

Seeing this error on the row.delete() method:

”   Cannot invoke an object which is possibly ‘undefined’  ”

 

The method is the following:

public removeRow(rowIndex: number) {
    const row = this.hierarchicalGrid.getRowByIndex(rowIndex);
    console.log(row);
    row.delete();
  }
It is the only error I´m getting in both the .ts and html components, any ideas on how to fix it?
Thanks,
Jose
Sign In to post a reply

Replies

  • 0
    Bozhidara Pachilova
    Bozhidara Pachilova answered on Dec 14, 2022 10:00 AM

    Hello Jose,

    Thank you for posting to Infragistics Community!

    I have been looking into your question and I assume that the “strictNullChecks” of the TSConfig compiler options is set to true. To explain the error origin, the object returned by the grid’s getRowByIndex method is of the RowType interface. As this interface is implemented by different objects representing rows, such as the IgxSummaryRow, which do not have a delete method, it is marked as optional.

    So, what I can suggest is leveraging optional chaining with the function call to the row’s delete method:

    row.delete?.();

    Here is also a small sample having the “strictNullChecks” enabled and demonstrating this suggestion. Please, test it on your side and let me know how it behaves.

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer

    • 0
      Jose Briz
      Jose Briz answered on Dec 14, 2022 1:59 PM

      Hi Bozhidara,

      Yes, strict is set to true.  

      The proposed solution works, thank you very much.

      Regards,

      Jose

      • 0
        Bozhidara Pachilova
        Bozhidara Pachilova answered on Dec 14, 2022 2:33 PM

        Hi Jose,

        Thank you for confirming that the suggestion works for you!

        Best regards,

        Bozhidara Pachilova

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Jose Briz
Favorites
0
Replies
3
Created On
Dec 14, 2022
Last Post
3 years, 2 months ago

Suggested Discussions

Created by

Created on

Dec 14, 2022 2:33 PM

Last activity on

Feb 12, 2026 9:44 AM