Announcement

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

    Displaying value from DisplayField instead of ValueField in a grid just as ComboBox

    Hi SmartGWT gurus,

    I'm writing to you since I haven't found any way to display value from DisplayField instead of ValueField in a ListGrid just as ComboBox does in a Form.

    I've modified the example at http://www.smartclient.com/smartgwt/showcase/#dropdown_grid_combobox_category as follows:

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.DataClass;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.grid.events.RecordClickEvent;
    import com.smartgwt.client.widgets.grid.events.RecordClickHandler;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class DropdownListGridSample implements EntryPoint {
    
        public void onModuleLoad() {
    
            DataSource supplyItemDS = ItemSupplyXmlDS.getInstance();
    
            OrderDataSource orderDataSource = new OrderDataSource();
    
            final DynamicForm form = new DynamicForm();
            form.setWidth(300);
            form.setIsGroup(true);
            form.setGroupTitle("Update");
            form.setDataSource(orderDataSource);
    
            TextItem buyer = new TextItem("buyerName");
    
            ListGridField itemField = new ListGridField("itemName");
            ListGridField unitsField = new ListGridField("units");
            ListGridField unitCostField = new ListGridField("unitCost");
    
            SelectItem item = new SelectItem("itemID");
            item.setWidth(240);
            item.setTitle("Item");
            item.setOptionDataSource(supplyItemDS);
            item.setValueField("SKU");
            item.setDisplayField("itemName");
            item.setPickListWidth(450);
            item.setPickListFields(itemField, unitsField, unitCostField);
    
            form.setItems(buyer, item);
            
            final ListGrid listGrid = new ListGrid();
            listGrid.setWidth(300);
            listGrid.setHeight(200);
            listGrid.setDataSource(orderDataSource);
            listGrid.setAutoFetchData(true);
            listGrid.addRecordClickHandler(new RecordClickHandler() {
              public void onRecordClick(RecordClickEvent event) {
                form.reset();
                form.editSelectedData(listGrid);
              }
            });
    
            VLayout vLayout = new VLayout();
            vLayout.setMembers(listGrid, form);
    
            vLayout.draw();
        }
    
        class OrderDataSource extends DataSource {
          public OrderDataSource() {
            addField(new DataSourceTextField("buyerName"));
            addField(new DataSourceTextField("itemID"));
            
            DataClass[] testData = new ListGridRecord[2];
            ListGridRecord data1 = new ListGridRecord();
            data1.setAttribute("buyerName", "John");
            data1.setAttribute("itemID", "33160700");
            testData[0] = data1;
    
            setClientOnly(true);
            setTestData(testData);
          }
        }
    }

    As you can see, when the grid is loaded, then ItemID field is populated with the Item ID per se, but it would be preferrable to show the DisplayField value just as it does when I pick the value up in the form, i.e. "File Expanding Portafile-black A-z #86000" instead of SKU "33160700". I wonder how can this be achieved?

    Many thanks!

    #2
    Hi,

    I've just found out the ValueFormater works fine for SelectItem but not for ComboBoxItem.

    Martin

    Comment

    Working...
    X