Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1015
Check for Undefined in igGrid Template
posted

What is the syntax to check for an undefined object property in the igGrid.  I'm using 12.2.20122.1021 with the IG Template Engine (which doesn't have much documentation).

var MyObj = [
	{
		Name: "Me",
		Comment: "Exists"
	},
	{
		Name: "Myself"
	}
];

For the above example, how would I check that the "comment" property is missing from the second object?

  • 5105
    Offline posted

    Hi dirq,

    The MyObj array is your grid dataSource I assume. In this case the check inside your Comment column template would be as follows:

    {{if ${Comment} === undefined}}Do something{{/if}}

    or

    {{if typeof ${Comment} === 'undefined'}}Do something{{/if}}

    Let me know if this helps or if I haven't understood your scenario well enough. I just want to mention that you cannot reference a specific array index inside the template members. Because the templating is designed to either loop through each data member and instantiate the template with it, or loop within nested array members using {{each}}. However it is not designed to directly access an array member like this ${Prop[3].Prop1}.

    Here are some good samples for you to look at: http://ko.infragistics.com/products/jquery/templating-engine/

    Here is documentation: http://help.infragistics.com/NetAdvantage/jQuery/2012.2/CLR4.0

  • 24671
    Suggested Answer
    posted

    Hi,

    i am not sure i fully understand the question, but something like this should do:

    if (typeof (MyObj[1].Comment) === "undefined") {

    // it's missing

    }

    Let me know if this helps. Thanks,

    Angel