Skip to content

Selected first row

New Discussion
Mahesh Sandhanshiv
Mahesh Sandhanshiv asked on Aug 11, 2021 4:25 PM

I am new in to the igx grid, so don't no how to selected first row  by default. So please help me into that.

Sign In to post a reply

Replies

  • 0
    Hristo Popov
    Hristo Popov answered on Feb 19, 2019 6:40 AM

    Hello,

    Thank you for contacting us!

    To be able to apply initial row selection, first you have to set the primaryKey and the rowSelectable property for the IgxGrid.

        

    The initial selection is made through the IgxGrid API:

        ngAfterViewInit(){
          this.grid.selectRows([1]);
          this.grid.markForCheck();
        }

    The row indexes start from 0.

    Keep in mind that the IgxGrid ChangeDetectionStrategy is OnPush, so when you apply changes to the Grid, you have notify it, which is done with the markForCheck() method.

    I made a StackBlitz sample, based on your requirement.

    Please, take a look at the sample and let me know if you have any questions.

    • 0
      Mahesh Sandhanshiv
      Mahesh Sandhanshiv answered on Feb 19, 2019 8:36 AM

      Thanks for your replay.

      Actually its working for me but i didn't need [rowSelectable]. When grid load it will select first row and service call there. So after select first row data fetch and it will bind to other component.

      In your case it will select first row but it will not throw any event. Below my code for your reference:

       handleRowSelection(event) {
          const targetCell = event.cell as IgxGridCellComponent;
          console.log(targetCell.row.rowData);
      }
      • 0
        Tihomir Iliev
        Tihomir Iliev answered on Feb 20, 2019 12:37 PM

        Hello Mahesh,

        I think you resolved your issue, but since I have a live sample of what you need, I'll post it here anyway – https://stackblitz.com/edit/igx-grid-preselected-first-row.

        Please let us know if you need further assistance.

      • 0
        shravani gowda
        shravani gowda answered on Aug 11, 2021 4:25 PM

        Hi,

           using below code i am able to select the row but i am not able to bind its value.

        <igx-grid #grid [data]="data" width="100%" height="500px" [primaryKey]="'ProductID'" [rowSelectable]="true">

        ngAfterViewInit(){
        this.grid.selectRows([1]);
        this.grid.markForCheck();
        }

        can you please help with this.

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Mahesh Sandhanshiv
Favorites
0
Replies
4
Created On
Aug 11, 2021
Last Post
4 years, 8 months ago

Suggested Discussions

Tags

Created by

Created on

Aug 11, 2021 4:25 PM

Last activity on

Aug 11, 2021 4:25 PM