This is a migrated thread and some comments may be shown as answers.

Call function in kendo grid column template

1 Answer 2165 Views
Grid
This is a migrated thread and some comments may be shown as answers.
alex
Top achievements
Rank 1
Iron
Veteran
alex asked on 17 Dec 2020, 11:43 AM

Hi I would like to know how do I call a function inside the kendo cloumn template?

I would like this function to take the cell value and return a result.

Something like this:

 

<kendo-grid-column field="Name"  [style]="{'text-align': 'right'}">
        <ng-template kendoGridCellTemplate let-value="value">
            <span>{{ myFunction(value) }}</span>
        </ng-template>
</kendo-grid-column>
 
 
 
public myFunction(n){
   if(n>0){
     return "ok";
  }else{
     return "do check";
  }
}

 

The function is not called in this case.

thanks,

regards

 

 

1 Answer, 1 is accepted

Sort by
0
Hetali
Telerik team
answered on 18 Dec 2020, 06:14 PM

Hi Alex,

The CellTemplateDirective does not pass the value field. In order to call a function with the cell value, use the dataItem field as seen below: 

<ng-template kendoGridCellTemplate let-dataItem let-rowIndex="rowIndex">
  <span>{{ myFunction(dataItem.UnitPrice) }}</span>
</ng-template>

In this StackBlitz example, the function is called using the dataItem field and works as expected.

I hope this helps. Please let me know if I can further assist you.

Regards,
Hetali
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
alex
Top achievements
Rank 1
Iron
Veteran
Answers by
Hetali
Telerik team
Share this question
or