We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Date.now() not working in template

Thread ID:

Created:

Updated:

Platform:

Replies:

143907 Apr 9,2019 07:20 AM UTC Apr 25,2019 11:12 AM UTC JavaScript - EJ 2 3
loading
Tags: General
Thijs
Asked On April 9, 2019 07:20 AM UTC

Hello, 

I want to use the Date.now() functionality in the template to compare a date with the current date, but it looks like the date object is always null, and when I use Date.now() the template renders as #TemplateName (as in an error raised probably?)

<##script type="text/x-jsrender" id="Status">
    ${if(DateFinished == null)}
    <##span>DateFinished is null!
    ${else if(Date == null)}                   <!--CONDITION IS ALWAYS TRUE!-->                
    <##span>Date is null!
   ${else if(DateFinished != null  && Date.now() > DateFinished)}    <!--THIS LINE BREAKS THE TEMPLATE, AND THE RESULT IS ALWAYS #Status-->
    <##span>Date is null!
    ${else}
    <##span>in last else statement
    ${/if}
<##/script>


P.s. How can I add code fragments into a forum post (with markup, and without have to use the <## I do above

Mydeen S N [Syncfusion]
Replied On April 10, 2019 09:23 AM UTC

Hi Thijs 
  
Greetings from Syncfusion support. 
  
Your requirement for using Date.now can be achieved by using the Custom Helpers in the template. Please find the sample custom helper and template in below code  
  
Custom helper:  
  
<script>  
window.processData = function(value){  
     
    if(value >=  5){  
        return '<span >Higher value</span>'  
    } else {  
        return  '  <span >'+ Date.now()+'</span>'  
    }  
}  
</script>  
  
template:  
<script id="template" type="text/x-jsrender" >  
   <div>${processData(data.EmployeeID)}</diV>  
</script>  
  
  
  
In the above example custom helper window.processData  we can process the data processing within the helper function and return the desired result to the template output and in the template section we can call the custom helper as in the above snippet and pass the desired arguments with data prefix (data.EmployeeID) to the helper for process and get desired output.  
  
Please get back to us, if you need any further assistance.  
  
  
Regards,    
Mydeen S N   
 


Thijs
Replied On April 24, 2019 09:33 PM UTC

Hello Mydeen,

Thx, this works!

The data prefix does not work (anymore) for me, I can only use the properties directly? is there something I can do to make the data prefix work? and is there a possibility that I can pass the entire data object as a parameter to the function?

Or use multiple parameters in the helper function like:

${getStatusFlag(StartDate, FinishedDate)}

window.getStatusFlag = function (date1, date2) {
     //do actions
}

in this example both dates are concatenated in the first parameter (date1) of the function

Kind regards,
Thijs

Mydeen S N [Syncfusion]
Replied On April 25, 2019 11:12 AM UTC

Hi Thijs, 
 
Thanks for the update. 
 
We have validated the defect you have initiated with us. Thank you for taking the time to report this issue and helping us improve our product. At Syncfusion, we are committed to fixing all validated defects (subject to technological feasibility and Product Development Life Cycle ) and including the defect fix in our upcoming weekly patch release. If you wish to receive this fix in a specific prior release product version please contact Syncfusion Support (backwards compatibility subject to technological feasibility and our Support SLA) You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link  
 
 
Regards, 
Mydeen S N 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon