Announcement

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

    FilterBuilder & ComboBoxItem

    Hi,

    Docs says that FilterBuilder is using editor type according to the Datasource type. I explicitly set field.setEditorType to ComboBoxItem as in code below.
    What I want is a drop down list of already entered values in the "continent" field.
    Although this works in grid row editing mode and in grid filter, it does not work in FilterBuilder.
    When choosing "continent" field in the FilterBuilder type of value is changed to the ComboBox but drop down list is empty.
    Does FilterBuilder support ComboBoxItem filled by this.DataSource ?
    Code:
    /*
     * MainEntryPoint.java
     *
     * Created on 1 październik 2009, 17:12
     *
     * To change this template, choose Tools | Template Manager
     * and open the template in the editor.
     */
    
    package org.yournamehere.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.fields.DataSourceBooleanField;
    import com.smartgwt.client.data.fields.DataSourceDateField;
    import com.smartgwt.client.data.fields.DataSourceFloatField;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.ListGridEditEvent;
    import com.smartgwt.client.widgets.form.FilterBuilder;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    /**
     *
     * @author michalg
     */
    public class MainEntryPoint implements EntryPoint {
       
        /** Creates a new instance of MainEntryPoint */
        public MainEntryPoint() {
        }
       
        /**
         * The entry point method, called automatically by loading a module
         * that declares an implementing class as an entry-point
         */
        public void onModuleLoad() {
    
            DataSource ds = new DataSource();
            ds.setDataFormat(DSDataFormat.XML);
            ds.setRecordXPath("/List/country");
            ds.setDataURL("data.xml");
    
            DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
            pkField.setHidden(true);
            pkField.setPrimaryKey(true);
    
            DataSourceTextField countryCodeField = new DataSourceTextField("countryCode", "Code");
            countryCodeField.setRequired(true);
    
            DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country");
            countryNameField.setRequired(true);
    
            DataSourceTextField capitalField = new DataSourceTextField("capital", "Capital");
            DataSourceTextField governmentField = new DataSourceTextField("government", "Government", 500);
    
            DataSourceBooleanField memberG8Field = new DataSourceBooleanField("member_g8", "G8");
    
            DataSourceTextField continentField = new DataSourceTextField("continent", "Continent");
            //continentField.setValueMap("Europe", "Asia", "North America", "Australia/Oceania", "South America", "Africa");
            ComboBoxItem comboBoxItem = new ComboBoxItem("continent");
            continentField.setEditorType(comboBoxItem);
    
            DataSourceDateField independenceField = new DataSourceDateField("independence", "Nationhood");
            DataSourceFloatField areaField = new DataSourceFloatField("area", "Area (km²)");
            DataSourceIntegerField populationField = new DataSourceIntegerField("population", "Population");
            DataSourceFloatField gdpField = new DataSourceFloatField("gdp", "GDP ($M)");
    
            ds.setFields(pkField, countryCodeField, countryNameField, capitalField, governmentField,
                    memberG8Field, continentField, independenceField, areaField, populationField,
                    gdpField);
    
           
            FilterBuilder filterBuilder = new FilterBuilder();
            filterBuilder.setDataSource(ds);
    
            ListGrid grid = new ListGrid();
            grid.setDataSource(ds);
            grid.setAutoFetchData(true);
            grid.setWidth(550);
            grid.setHeight(224);
            grid.setCanEdit(true);
            grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
    
            VLayout main = new VLayout();
            main.addMember(filterBuilder);
            main.addMember(grid);
            main.draw();
        }
       
    }

    #2
    Explicitly set optionDataSource. Using the surrounding form's DataSource as an optionDataSource is a default behavior for forms but not FilterBuilder.

    Comment


      #3
      Setting optionDataSource explicity before ds.setFields() (as in following code) causes an error:
      Error: Fields cannot be added to a DataSource after the underlying component has been created.
      Code:
          public void onModuleLoad() {
      
              DataSource ds = new DataSource();
              ds.setDataFormat(DSDataFormat.XML);
              ds.setRecordXPath("/List/country");
              ds.setDataURL("data.xml");
      
              DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
              pkField.setHidden(true);
              pkField.setPrimaryKey(true);
      
              DataSourceTextField countryCodeField = new DataSourceTextField("countryCode", "Code");
              countryCodeField.setRequired(true);
      
              DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country");
              countryNameField.setRequired(true);
      
              DataSourceTextField capitalField = new DataSourceTextField("capital", "Capital");
              DataSourceTextField governmentField = new DataSourceTextField("government", "Government", 500);
      
              DataSourceBooleanField memberG8Field = new DataSourceBooleanField("member_g8", "G8");
      
              DataSourceTextField continentField = new DataSourceTextField("continent", "Continent");
              //continentField.setValueMap("Europe", "Asia", "North America", "Australia/Oceania", "South America", "Africa");
              ComboBoxItem comboBoxItem = new ComboBoxItem("continent");
              comboBoxItem.setOptionDataSource(ds);
              continentField.setEditorType(comboBoxItem);
      
              DataSourceDateField independenceField = new DataSourceDateField("independence", "Nationhood");
              DataSourceFloatField areaField = new DataSourceFloatField("area", "Area (km²)");
              DataSourceIntegerField populationField = new DataSourceIntegerField("population", "Population");
              DataSourceFloatField gdpField = new DataSourceFloatField("gdp", "GDP ($M)");
      
              ds.setFields(pkField, countryCodeField, countryNameField, capitalField, governmentField,
                      memberG8Field, continentField, independenceField, areaField, populationField,
                      gdpField);
      
             
              FilterBuilder filterBuilder = new FilterBuilder();
              filterBuilder.setDataSource(ds);
      
              ListGrid grid = new ListGrid();
              grid.setDataSource(ds);
              grid.setAutoFetchData(true);
              grid.setWidth(550);
              grid.setHeight(224);
              grid.setCanEdit(true);
              grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
      
              VLayout main = new VLayout();
              main.addMember(filterBuilder);
              main.addMember(grid);
              main.draw();
          }
      Setting optionDataSource after ds.setFields does not change anything - still no drop down options in FilterBuilder continent field.
      Code:
          public void onModuleLoad() {
      
              DataSource ds = new DataSource();
              ds.setDataFormat(DSDataFormat.XML);
              ds.setRecordXPath("/List/country");
              ds.setDataURL("data.xml");
      
              DataSourceIntegerField pkField = new DataSourceIntegerField("pk");
              pkField.setHidden(true);
              pkField.setPrimaryKey(true);
      
              DataSourceTextField countryCodeField = new DataSourceTextField("countryCode", "Code");
              countryCodeField.setRequired(true);
      
              DataSourceTextField countryNameField = new DataSourceTextField("countryName", "Country");
              countryNameField.setRequired(true);
      
              DataSourceTextField capitalField = new DataSourceTextField("capital", "Capital");
              DataSourceTextField governmentField = new DataSourceTextField("government", "Government", 500);
      
              DataSourceBooleanField memberG8Field = new DataSourceBooleanField("member_g8", "G8");
      
              DataSourceTextField continentField = new DataSourceTextField("continent", "Continent");
              //continentField.setValueMap("Europe", "Asia", "North America", "Australia/Oceania", "South America", "Africa");
              ComboBoxItem comboBoxItem = new ComboBoxItem("continent");
              continentField.setEditorType(comboBoxItem);
      
              DataSourceDateField independenceField = new DataSourceDateField("independence", "Nationhood");
              DataSourceFloatField areaField = new DataSourceFloatField("area", "Area (km²)");
              DataSourceIntegerField populationField = new DataSourceIntegerField("population", "Population");
              DataSourceFloatField gdpField = new DataSourceFloatField("gdp", "GDP ($M)");
      
              ds.setFields(pkField, countryCodeField, countryNameField, capitalField, governmentField,
                      memberG8Field, continentField, independenceField, areaField, populationField,
                      gdpField);
      
              comboBoxItem.setOptionDataSource(ds);
             
              FilterBuilder filterBuilder = new FilterBuilder();
              filterBuilder.setDataSource(ds);
      
              ListGrid grid = new ListGrid();
              grid.setDataSource(ds);
              grid.setAutoFetchData(true);
              grid.setWidth(550);
              grid.setHeight(224);
              grid.setCanEdit(true);
              grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
      
              VLayout main = new VLayout();
              main.addMember(filterBuilder);
              main.addMember(grid);
              main.draw();
          }

      Comment


        #4
        Can anyone managed to have ComboBoxItem with OptionDataSource set in FilterBuilder working ?
        Thanks,
        MichalG

        Comment


          #5
          Anybody ?

          Anybody ?
          Is OptionDataSource in the FilterBuilder field possible ?
          I only managed to make drop-down working with ValueMap in FilterBuilder.
          Please help.
          MichalG

          Comment


            #6
            A solution

            Add this code to your datasource class (in my case it was the user datasource)
            Code:
            final DataSourceIntegerField office = new DataSourceIntegerField("officeId", "Office Location");
            office.setEditorType(new ComboBoxItem());
            OfficeDS.getInstance().fetchData(null, new DSCallback(){
                @Override
                public void execute(DSResponse response, Object rawData, DSRequest request) {
                    office.setValueMap(response.getDataAsRecordList().getValueMap("id", "name"));
            }});

            Comment


              #7
              Already fixed in trunk:
              http://code.google.com/p/smartgwt/issues/detail?id=376
              But thanks,
              MichalG

              Comment


                #8
                Are you sure this has been fixed?

                I have exactly the same issue and context as explained here: A filterBuilder that does not display options for FK fields, happens for all browsers, fk is well defined as it works in other editors, other fields work well including valueMap fields.

                I have used the december 2013 distributions of smartgwtpro3.1p and smartgwtee trial edition.

                Comment


                  #9
                  ComboBox'es as FK in FilterBuilder are working for me since long time.
                  Post a simple, runable test case so we can look at it.
                  MichalG

                  Comment


                    #10
                    Enclosed is the attachment. As you can see, the valueMap field works but the fk fields do not offer any values.

                    https://drive.google.com/file/d/0BxLF5ofEsJ2Wa2o4VlAycXptdlU/edit?usp=sharing

                    https://drive.google.com/file/d/0BxLF5ofEsJ2Wb0ptSmVKVFBSTWM/edit?usp=sharing

                    Comment

                    Working...
                    X