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
20
igGrid column template - if statement inside each block
posted

Hi! I'm currently trying to initialize an igGrid with some conditional templating, but I'm having some problems when I use "if" statement inside "each" blocks.

Here's my columns variable:

var tempColumns = [
{ headerText: "header1", key: "Cells", dataType: "object", template: "{{each ${Cells} }} {{if ${Cells.Nome} != ''}} ${Cells.Nome} {{else}} no name {{/if}} {{/each}}", width: 250 }
];

My source list:

var tempSourceList2 = [{ Cells : [{ ID : 1, Nome: "Nome1" }, { ID: 2, Nome: "Nome2"}] },
{ Cells : [{ ID: 1, Nome: "" }, { ID: 2, Nome: "Nome3"}] }
];

But the result inside the cells on the rendered igGrid is:

if ( Nome1 != '') {result += args[0]; } else {result += args[1];} if ( Nome2 != '') {result += args[0]; } else {result += args[1];}

if ( != '') {result += args[0]; } else {result += args[1];} if ( Nome3 != '') {result += args[0]; } else {result += args[1];}


Does not the each block supports if statement?

Thank you for your attention.

Parents
No Data
Reply
  • 6279
    Suggested Answer
    posted

    Hi Paulo,

    I'm afraid that the grid's templating capabilities do not support the "each" statement.

    However, the usage you're describing can be implemented using a formatter function instead of a template.

    You can see a basic sample of how the formatter function is used in the official sample Column Formatter.

    Hope this helps,
    Borislav 

Children
No Data