Skip to content

Infragistics Community Forum / Web / Ignite UI for Angular / Set Focus on first cell of new row

Set Focus on first cell of new row

New Discussion
Jason Jhuboo
Jason Jhuboo asked on Sep 3, 2021 12:11 PM

I am using an onGridKeydown event to add a new row of an igx-grid which is editable by the user.

The question I have is how can I set focus on the first cell of the new row when my onGridKeydown event fires?

Here is an example of my code.

public customKeydown(args: IGridKeydownEventArgs) {

const target: IgxGridCellComponent = args.target as IgxGridCellComponent;
const evt: KeyboardEvent = args.event as KeyboardEvent;
const type = args.targetType;

if (type === ‘dataCell’ && evt.key.toLowerCase() === ‘arrowdown’) {

const currentRowId = +this.grid1.data[this.grid1.data.length – 1].Id;
const newRowId = currentRowId + 1;

this.grid1.addRow({
Id: newRowId,
Code: ”,
Currency: ”,
Amount: null
});

this.grid1.updateRow({}, newRowId); // Sets focus on new row.

// Logic to set  focus on first cell……???

}

}

Sign In to post a reply

Replies

  • 0
    Martin Asenov
    Martin Asenov answered on Jan 20, 2020 9:45 AM

    Hello Jason,

    Thank you for posting in our community.

    My suggestion is to use the navigateTo method of igxGrid:

    //...
    this.grid1.navigateTo(newRowId, 0, (args) => { args.target.nativeElement.focus(); });
    //...

    • 0
      Hitesh Patil
      Hitesh Patil answered on Aug 31, 2021 4:57 PM

      Hi, I tried this solution but it says 'ERROR TypeError: Cannot read property 'navigateTo' of undefined'. Could you please help me understand what's wrong?

      • 0
        Martin Asenov
        Martin Asenov answered on Sep 3, 2021 12:11 PM

        Hello,

        Thank you for posting in our community.

        I have created a StackBlitz sample for you reference. Please test it on your side and let me know if it meets your requirement.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Jason Jhuboo
Favorites
0
Replies
3
Created On
Sep 03, 2021
Last Post
5 years ago

Suggested Discussions

Created by

Created on

Sep 3, 2021 12:11 PM

Last activity on

Feb 23, 2026 6:13 AM