ClientTemplate causes error

3 posts, 0 answers
  1. Alex
    Alex avatar
    76 posts
    Member since:
    May 2015

    Posted 25 Jan 2017 Link to this post

    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. Ianko
    Ianko avatar
    1955 posts

    Posted 27 Jan 2017 Link to this post

    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:


    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.
  3. carlos
    carlos avatar
    1 posts
    Member since:
    Mar 2021

    Posted 08 Mar Link to this post

    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 .

Back to Top