Package com.extjs.gxt.ui.client.core

Examples of com.extjs.gxt.ui.client.core.XTemplate

  • Basic math support


    The following basic math operators may be applied directly on numeric data values:

     + - * / 
    For example:
     public native String getTemplate() /*-{ return ['<p>Name: {name}</p>', '<p>Kids: ', '<tpl for="kids">', '<tpl if="age &gt; 1">',  // <-- Note that the > is encoded '<p>{#}: {name}</p>',  // <-- Auto-number each item '<p>In 5 Years: {age+5}</p>',  // <-- Basic math '<p>Dad: {parent.name}</p>', '</tpl>', '</tpl></p>' ].join(""); ); template.overwrite(someElement, Util.getJsObject(person)); 
  • Execute arbitrary inline code with special built-in template variables


    Anything between {[ ... ]} is considered code to be executed in the scope of the template. There are some special variables available in that code:

    This example demonstrates basic row striping using an inline code block and the xindex variable:

     public native String getTemplate() /*-{ return ['<p>Name: {name}</p>', '<p>Company: {[values.company.toUpperCase() + ", " + values.title]}</p>', '<p>Kids: ', '<tpl for="kids">', '<div class="{[xindex % 2 === 0 ? "even" : "odd"]}">', '{name}', '</div>', '</tpl></p>' ].join(""); ); template.overwrite(someElement, Util.getJsObject(person)); 
  • Template member functions


    One or more member functions can be specified in a configuration object passed into the XTemplate constructor for more complex processing:

     var tpl = new Ext.XTemplate( '<p>Name: {name}</p>', '<p>Kids: ', '<tpl for="kids">', '<tpl if="this.isGirl(name)">', '<p>Girl: {name} - {age}</p>', '</tpl>', // use opposite if statement to simulate 'else' processing: '<tpl if="this.isGirl(name) == false">', '<p>Boy: {name} - {age}</p>', '</tpl>', '<tpl if="this.isBaby(age)">', '<p>{name} is a baby!</p>', '</tpl>', '</tpl></p>', { // XTemplate configuration: compiled: true, disableFormats: true, // member functions: isGirl: function(name){ return name == 'Sara Grace'; }, isBaby: function(age){ return age < 1; } } ); tpl.overwrite(panel.body, data); 

  •     ToolBar toolBar = new ToolBar();
        toolBar.add(new Button("Apply Template", new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            XTemplate tpl = XTemplate.create(getTemplate());
            xpanel.removeAll();
            xpanel.addText(tpl.applyTemplate(Util.getJsObject(person, 3)));
            xpanel.layout();
          }
        }));
        xpanel.setTopComponent(toolBar);
       
        final ContentPanel cpanel = new ContentPanel();
        cpanel.setHeading("XTemplate Test");
        cpanel.setWidth(500);
        cpanel.setBodyStyleName("pad-text");
       
        final Html html = new Html();
        html.setStyleName("pad-text");

        final TextArea area = new TextArea();
        area.setSize(485, 150);
       
        toolBar = new ToolBar();
        toolBar.add(new Button("Apply Template", new SelectionListener<ButtonEvent>() {
          @Override
          public void componentSelected(ButtonEvent ce) {
            String template = area.getValue();
            XTemplate tpl = XTemplate.create(template);
            tpl.overwrite(html.getElement(), Util.getJsObject(person, 3));
          }
        }));
        cpanel.setTopComponent(toolBar);
       
        StringBuilder sb = new StringBuilder();
    View Full Code Here


              "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.<br/><br/>Aliquam commodo ullamcorper erat. Nullam vel justo in neque porttitor laoreet. Aenean lacus dui, consequat eu, adipiscing eget, nonummy non, nisi. Morbi nunc est, dignissim non, ornare sed, luctus eu, massa. Vivamus eget quam. Vivamus tincidunt diam nec urna. Curabitur velit.");
        }

        List<ColumnConfig> configs = new ArrayList<ColumnConfig>();

        XTemplate tpl = XTemplate.create("<p><b>Company:</b> {name}</p><br><p><b>Summary:</b> {desc}</p>");

        RowExpander expander = new RowExpander();
        expander.setTemplate(tpl);

        configs.add(expander);
    View Full Code Here

        sb.append("<b>Last:</b> {last}<br>");
        sb.append("<b>Change:</b> {[new Number(values.change).toFixed(2)]}<br>");
        sb.append("<b>Updated:</b> {date:date(\"MM/dd/y\")}<br>");
        sb.append("</div>");

        final XTemplate template = XTemplate.create(sb.toString());
        final HTML html = new HTML();
        html.setWidth("160px");
      
        template.overwrite(html.getElement(), Util.getJsObject(stock));
        hp.add(html);
        // update template when model changes
        stock.addChangeListener(new ChangeListener() {
          public void modelChanged(ChangeEvent event) {
            template.overwrite(html.getElement(), Util.getJsObject(stock));
          }
        });

        FormPanel panel = new FormPanel();
        panel.setHeaderVisible(false);
    View Full Code Here

    TOP

    Related Classes of com.extjs.gxt.ui.client.core.XTemplate

    Copyright © 2018 www.massapicom. All rights reserved.
    All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.