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

ClientTemplate causes error

2 Answers 175 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 25 Jan 2017, 03:02 PM

I was having some issues with a grid where I was getting an error saying that Description is not field that can be called on a null value, or something along those lines. TimeType is of type TimeTypeViewModel.

public class TimeTypeViewModel
{
    public override string ID { get; set; }
    public override string Description { get; set; }
}

 

columns.Bound(p => p.TimeType).Hidden(true).ClientTemplate("#= (typeof TimeType != 'undefined') ? TimeType.Description : ''#");

 

but the following code doesn't cause me any issues

but code doesn't cause me any issues

columns.Bound(p => p.TimeType).Hidden(true).ClientTemplate("#= typeof TimeType == 'undefined' || TimeType == null ? '' : TimeType.Description #");

 

Why is this? It seems that all the values (i.e. 'TimeType.Description') are being evaluated in the expression before actually checking to see if they should be evaluated based on the inline if condition. Is this a bug? Is this me not understanding how templates work? Is my code somehow bad, or only works on certain types?

2 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 27 Jan 2017, 02:15 PM

Hello Alex,

The behavior you get is related to the template syntax, but to the ternary operation. 

The error thrown is because the TimeType is null, not undefined. Therefore, the ternary operation is evaluated to true. You can get more details about the difference in these two StackOverflow threads:

Regards,

Ianko
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
carlos
Top achievements
Rank 1
answered on 09 Mar 2021, 05:00 AM
The value 'undefined' denotes that a variable has been declared, but hasn't been assigned any value. On the other hand, Javascript null refers to a non-existent object, which basically means 'empty' or 'nothing'. They're both values usually used to indicate the absence of something . Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object .


Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Ianko
Telerik team
carlos
Top achievements
Rank 1
Share this question
or