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
1010
Template function available?
posted

Hi,

Is there an example, when creating the column definitions, to pass in a function for the template option?

Right now we are using templates, and passing in 

template: $("#tmplName").html();

We have defined a template for a column, with several if/else statements. But we have an extra condition, where if true, then would like to add a class on the resulting element.

I've attached sample of template. 

In order to add the extra condition, I would have to copy the template twice, and place each copy in an if else block. But if I can pass in a function, then maybe I can add the class dynamically using jquery.

Can you please advise?

CR

  • 18204
    Suggested Answer
    Offline posted

    Hi CR,

    Thank you for posting in our forums!

    It looks like your template sample did not attach properly to the thread.  But based on your description, you can handle the igGrid's rowsRendered event to dynamically alter your templated cells.

    The rowsRendered event fires after the templates are applied, so you can use a placeholder class for any logic you want to handle.  You can see a demonstration in this jsFiddle I have created.

    In the fiddle, you can see the "dynamicTmplLogic" class applied to the template.  In the rowsRendered event, I loop through each element with this class and get the row's data from the primaryKey for the row by calling the findRecordByKey method.  I can then use that data to determine how to handle the template.

    If you have any further questions or concerns with this, please let me know and I will be glad to help.