1. #1
    Sencha User
    Join Date
    Jul 2009
    Posts
    16
    Vote Rating
    0
    sajjan.sarkar is on a distinguished road

      0  

    Question Unable to set Template on ListField

    Unable to set Template on ListField


    Hi,
    I'm new to GXT and apologize in advance if my question is a repeat( I couldnt any similar questions though).

    I'm trying to build a listfield of Approvers, but want to display in the format "LastName,FirstName".
    Here is my Approver stub:
    Code:
    /** * 
     */
    package com.peoplenet.OrderEntry.client;
    
    
    import com.extjs.gxt.ui.client.data.BaseModelData;
    /**
     * @author sajjan sarkar
     *
     */
    public class Approver extends BaseModelData{
            
        private static final String userID = "userID";
        private static final String firstName = "firstName";
        private static final String lastName = "lastName";
        
    
    
        public Approver()
        {
            super();
        }
        
        public int getUserID() {
            return get(userID);
        }
    
    
        public void setUserID(int userID) {
            set(Approver.userID,userID);
        }
    
    
        public int getFirstName() {
            return get(firstName);
        }
    
    
        public void setFirstName(int firstName) {
            set(Approver.firstName,firstName);
        }
    
    
        public int getLastName() {
            return get(lastName);
        }
    
    
        public void setLastName(int lastName) {
            set(Approver.lastName, lastName);
        }
    }
    And here is my listfield code:
    Code:
    ....
    approversListField = new ListField<Approver>();        
    approversListField.setEmptyText("employee last name");         
            approversListField.setTemplate("{lastName},{firstName}");
            approversListField.setDisplayField("lastName");  
            approversListField.setFieldLabel("Approvers *");            
            approversListField.setId("approvers");
            approversListField.setStore(dataStores.getApprovers());
    • When I remove the setTemplate call I can see the LastNames of the employees, so I do have the data.
    Please let me know what I'm missing out!
    Thanks a lot!
    ......

  2. #2
    Sencha User
    Join Date
    Jul 2009
    Posts
    16
    Vote Rating
    0
    sajjan.sarkar is on a distinguished road

      0  

    Cool SOLVED: Specify javascript HTML template

    SOLVED: Specify javascript HTML template


    Hi,

    Found the solution myself.. this worked
    Code:
    private void loadApprovers() {        
            approversListField = new ListField<Approver>();
            approversListField.setEmptyText("employee last name");     
            approversListField.setTemplate(getTemplate());        
            approversListField.setFieldLabel("Approvers *");            
            approversListField.setId("approvers");
            approversListField.setStore(dataStores.getApprovers());
        }
        private native String getTemplate() /*-{
        return  [
        '<tpl for=".">',
        '<div class="x-combo-list-item" qtip="{userID}" qtitle="UserID:">{lastName},{firstName}</div>',
        '</tpl>'
        ].join("");
      }-*/;

Tags for this Thread