We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How can we call a methode form the ej control in Angular 2 Typecript with code?

Thread ID:

Created:

Updated:

Platform:

Replies:

126231 Oct 3,2016 03:55 AM Oct 7,2016 01:00 AM JavaScript 5
loading
Tags: ejGrid
j.nord
Asked On October 3, 2016 03:55 AM

Hi,

how can we call a methode in Angular 2?

Example:

We want marked a record in the grid (selectedRows?). Then we want sort the grid (sortColumn).

How can we select the grid in the dom, to call the methods?
@ViewChild('grid') doesn't work. We get only properties.

Regards

j.nord


Venkatesh Ayothi Raman [Syncfusion]
Replied On October 4, 2016 09:29 AM

Hi Jurgen, 

Thank you for contacting Syncfusion support. 

We can call the Grid methods from @Viewchild decorator. The problem is @Viewchild will be set only after ngAfterViewInit event fired.So, we suggest to use code like as follows, code example, 
Code example: 
export class AppComponent { 
    @ViewChild('grid')  
    public grid; 
    public gridData; 
    public dataManager; 
       data:array; 
    fieldsvalues:object; 
    value:string; 
     
    ngAfterViewInit() { 
        this.grid.widget.sortColumn('OrderID');/*call the sort column method */ 
        this.grid.widget.selectRows(2);  /*call the select rows method for select the record*/ 
    } 

Please let us know, if you have any further assistance. 

Regards, 
Venkatesh Ayothiraman. 


j.nord
Replied On October 4, 2016 10:30 AM

Hi Venkatesh,

thanks for answer but sorry so it doesn't work under Angular 2.

We have the Methode in ngAfterViewInit.

But where do you get the "widget" ?

To define the grid the code under Angular2 is:

@ViewChild('myGrid') grid: ElementRef;

And then you get under ngAfterViewInit:

this.grid.nativeElement. ??

and not "widgets"

How do you get the "widget" ???




Venkatesh Ayothi Raman [Syncfusion]
Replied On October 5, 2016 09:40 AM

Hi Jurgen, 

Thank you for the update. 

We went through your code example and found that you are using” @ViewChild('myGrid') grid: ElementRef” and this is the cause we were unable to get the grid widget. So, we suggest you to use EJComponents instead of ElementRef. Please refer to the code example, 
Code example: 
/// <reference path="../ej/ej.web.all.d.ts" /> 
/// <reference path="../ej/Jquery.d.ts" /> 
 
 
import {Component} from '@angular/core'; 
import {CORE_DIRECTIVES, FORM_DIRECTIVES} from '@angular/common'; 
import {EJ_GRID_COMPONENTS} from 'ej/grid.component'; 
import {EJComponents} from 'ej/core'; 
import {ViewChild, Injectable} from '@angular/core'; 
@Component({ 
    selector: 'ej-app', 
    templateUrl: 'app/app.component.html', 
    directives: [EJ_GRID_COMPONENTS, CORE_DIRECTIVES] 
}) 
export class AppComponent { 
  
@ViewChild('mygrid') grid:EJComponents<any, any> ; //you can get widget to extend the EJComponents instead of Elementref 
        public gridData; 
        public dataManager; 
           . . . 
        ngAfterViewInit() { 
 
            this.grid.widget.sortColumn('OrderID','ascending');/*call the sort column method */ 
 
        } 
       . . . 


Regards, 
Venkatesh Ayothiraman. 


j.nord
Replied On October 6, 2016 06:07 AM

Hi Venkatesh,

it works. Thank you for the answer.

Regards

j.nord

Venkatesh Ayothi Raman [Syncfusion]
Replied On October 7, 2016 01:00 AM

Hi Jurgen, 
Thanks for the feedback. 
We are happy to hear that your requirement is achieved. 
Regards, 
Venkatesh Ayothiraman. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;