O'Reilly logo

Ext JS 4 Web Application Development Cookbook by Stuart Ashworth, Andrew Duncan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Formatting dates within an Ext.XTemplate

Dates are one of the most common data types that need formatting before being displayed to the user. This is no different when creating Ext.XTemplates for use in plain components or more complex components such as Data Views.

This recipe will describe the best way to perform this formatting within an Ext.XTemplate.

How to do it...

  1. First, we will create a simple Ext.XTemplate and render it to the document's body, applying a simple data object, containing a date:
    var data = {
        date: '5/8/1986 12:30:00'
    };
    
    var tpl = new Ext.XTemplate('{date}');
    
    tpl.overwrite(Ext.getBody(), data); // outputs '5/8/1986 12:30:00'
  2. We then use the date function, passing it a formatting string to format the date property:
    var tpl = new ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required