angulartemplateskendo-gridkendo-ui-angular2kendo-template

Call function in kendo grid column template


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="tot"  [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


Solution

  • There is no field called value to be passed.

    Try to change:

    <kendo-grid-column field="tot"  [style]="{'text-align': 'right'}">
        <ng-template kendoGridCellTemplate let-value="value">
            <span>{{ myFunction(value) }}</span>
        </ng-template>
    </kendo-grid-column>
    

    to:

    <kendo-grid-column field="tot"  [style]="{'text-align': 'right'}">
        <ng-template kendoGridCellTemplate let-dataItem>
            <span>{{ myFunction(dataItem) }}</span>
        </ng-template>
    </kendo-grid-column>
    

    and use myFunction accordingly.

    Please read https://www.telerik.com/kendo-angular-ui/components/grid/api/CellTemplateDirective to have a better understanding.