How to assign 2 fields for one column based on condition in Kendo Grid Angular 4

Viewed 2836

Im using Kendo Grid with Angular 4.

I have 2 fields 'DateCreated' and 'DateModified' and i want to assign these fields to column 'Date Modified'. if the value in 'DateModified' field is null then the 'DateCreated' field value will get assign to the column. and when the both values are present then the 'DateModified' value gets assign.

tried with *ngIf but i can assign only one field.

Here is my code..

   <kendo-grid-column field="RecordModifiedDate" title="Date Modified">
       <ng-template kendoGridCellTemplate let-dataItem>
           <div *ngIf="dataItem.RecordModifiedDate = null">{{ (dataItem.DateCreated) | date: 'MM-dd-yyyy HH:mm:ss' }}</div>
            </ng-template>
               </kendo-grid-column>

Thanks

2 Answers

You need to add one more if condition to display date modified.

<kendo-grid-column field="RecordModifiedDate" title="Date Modified">
  <ng-template kendoGridCellTemplate let-dataItem>
    <div *ngIf="dataItem.RecordModifiedDate == null">{{ (dataItem.DateCreated) | date: 'MM-dd-yyyy HH:mm:ss' }}</div>
    <div *ngIf="dataItem.RecordModifiedDate !== null">{{ (dataItem.RecordModifiedDate) | date: 'MM-dd-yyyy HH:mm:ss' }}</div>
  </ng-template>
</kendo-grid-column>

you can set your condition in the interpolation like this

<kendo-grid-column field="RecordModifiedDate" title="Date Modified">
       <ng-template kendoGridCellTemplate let-dataItem>
           <div>{{ (dataItem.RecordModifiedDate==null) ? dataItem.DateCreated | date: 'MM-dd-yyyy HH:mm:ss' : dataItem.RecordModifiedDate | date: 'MM-dd-yyyy HH:mm:ss' }}</div>
       </ng-template>
</kendo-grid-column>
Related