Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Formatting the selected value of a SelectItem (databound)

    Hello,

    Using SmartGWT 3.0 power.

    I'm pretty sure what I want to achieve is possible, but I don't know how.

    I got the following SelectItem, as an editor of a ListGridField:
    Code:
    ListGridField tea = new ListGridField("Teacher_id", teacherMessages.name_single());
    
    SelectItem teaSel = new SelectItem();
    teaSel.setOptionDataSource(DataSource
    				.get("Teacher"));
    teaSel.setValueField("Teacher_id");
    teaSel.setDisplayField("surname");
    teaSel.setAllowEmptyValue(true);
    teaSel.setPickListWidth(700);
    ListGrid TeacherListGrid = new ListGrid();
    TeacherListGrid.setShowFilterEditor(true);
    TeacherListGrid.setFilterOnKeypress(true);
    ListGridField t1 = new ListGridField("tussenvoegsel", teacherMessages.tussenvoegsel());
    t1.setWidth(40);
    teaSel.setPickListFields(
    		new ListGridField("firstname", teacherMessages.firstname()),
    		t1,
    		new ListGridField("surname", teacherMessages.surname()),
    		new ListGridField("companyName", teacherMessages.companyName())
    );	
    		
    teaSel.setPickListProperties(TeacherListGrid);
    teaSel.setValueFormatter(new FormItemValueFormatter(){
    	public String formatValue(Object value, Record r,
    			DynamicForm form, FormItem item) {
    		Object v = value;
    				
    		String f = r.getAttribute("firstname")==null ? "" : r.getAttribute("firstname");
    		String t = r.getAttribute("tussenvoegsel")==null ? "" : r.getAttribute("tussenvoegsel");
    		String s = r.getAttribute("surname")==null ? "" : r.getAttribute("surname"); 
    
    		if(r.getAttribute("surname") == null || "".equals(r.getAttribute("surname"))) {
    			return r.getAttribute("companyName");
    		}
    		else {
    			return f+t+s;
    		}
    	}
    });
    		
    tea.setEditorType(teaSel);
    tea.setDisplayField("surname");
    So, on clicking the SelectItem, a drop-down-ListGrid is displayed with records from the optiondatasource "Teacher". This will be containing first / last name combo's. Upon selection, I 'd like to display this in the SelectItem. Now It shows only the firstname. I tried, as you can see, SelectItem.setValueFormatter, to no avail (the Record r parameter doesn't seem to be updated to reflect the selected record in the drop down listgrid)

    Which API (on SelectItem probably?) should I use?

    #2
    I am still looking for a solution. A shorter way to ask this question is:

    A selectItem has a method setDisplayField(String fieldName);

    Is it possible to format the value displayed in this field?



    If it is not possible, could you reply here saying so? Would be a nice feature! I have a few use cases in different projects that would benefit from this. I'd imagine you could pass in the current selected record, to also use other fields than the displayField in the formatting

    Comment


      #3
      There are samples of this in the Showcase under ComboBox.

      Comment

      Working...
      X