jQWidgets Forums

jQuery UI Widgets Forums Angular How to get jqx component with dynamical Id ?

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by  Grigoriy Grachev 7 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author

  • Grigoriy Grachev
    Participant

    Here Id is static string ‘StaticGridId’. I can get jqxGridComponent via decorator @ViewChild(‘StaticGridId’). Then I can work with the grid. For example, this.myGrid.getselectedrowindex(). This code works fine:

    
    template:'
    
    <jqxGrid #StaticGridId
             [width]="'100%'"
             [source]="source"
             [columns]="columns"        
    </jqxGrid>';
    
    export class GridComponent {
    
    @Input() private source: any; 
    @Input() private columns: any; 
    
    @ViewChild(‘StaticGridId’) myGrid: jqxGridComponent;
    
    public getRecordId ():string {
    return this.myGrid.getselectedrowindex()
    }
    }
    

    But I need to use variable id for elements. I try to do this:

    
    
    template:'
    <jqxGrid #{{elementId}} <!-— can I do that? -->
             [width]="'100%'"
             [source]="source"
             [columns]="columns"        
    </jqxGrid>';
    
    export class GridComponent {
    
    @Input() private elementId: string; 
    @Input() private source: any; 
    @Input() private columns: any; 
    
    @ViewChild(this.elementId) myGrid: jqxGridComponent; // here I get an error
    
    public getRecordId ():string {
    return this.myGrid.getselectedrowindex()
    }
    }
    

    How to work jqx component with variable Id ?


    Martin
    Participant

    Hello Grigoriy,

    Angular allows using only static template references. You cannot pass a variable there.
    Why don’t you access the grid in the parent component?
    Can you explain what would you like to achieve with this, so we can give you an optimal solution?

    Best Regards,
    Martin

    jQWidgets Team
    http://www.jqwidgets.com/


    Grigoriy Grachev
    Participant

    Thank you, I will do it via parent component.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.