Announcement

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

    FilterBuilder widget - Datasource fields options populating blank

    Hi,
    I am using filter builder component of smartgwt. Everything works fine except the fields where values is a list of dropdown. The dropdown pouplates with lots of blank values.I am not able to find any hook like editorcustomizer etc.
    Can you please guide how can I show the data correctly and show the data according to criteria.

    Code:
    FilterBuilder filterBuilder = new FilterBuilder();
    filterBuilder.setDataSource(myDS);
    
    In ds.xml my field is defined as :
     <field name="myField" type="integer" foreignKey="OtherDS.primaryKeyId" displayField="myValue" title="Hand"/>
    PFB the image with blank options for this field :

    Click image for larger version

Name:	Capture.PNG
Views:	115
Size:	9.6 KB
ID:	258187

    Is it possible to send a criteria to show filtered value here? Also please suggest why the options are showing as empty. I can't see anything on smartgwt console. No fetch calls.

    Thanks in advance.

    #2
    This would normally initiate a fetch, and the fact that the drop-down is populated with blanks very strongly suggests that a fetch was initiated and some data received, so your claim that no fetch occurred is probably not accurate.

    Instead, the response was probably broken in some way: no data for the configured displayField ("myValue") in the related records. The same thing would happen for a DynamicForm or ListGrid, which probably means that you've added additional properties or overrides to make this work in other components. We would recommend instead making the definition the DataSource uses actually work.

    You can customize the FormItem used to pick the value for filtering via getValueFieldProperties().

    Comment


      #3
      Thanks Isomorphic ,
      I can see the intermittent fetch calls in console with the data that should come but on UI the list is big and empty. If I select any records it shows some ID. I tried getValueFieldProperties() as suggested by you like below.

      Code:
        filterBuilder = new FilterBuilder() {
      
                  @Override
                  public FormItem getValueFieldProperties(FieldType type, String fieldName, OperatorId operatorId, ValueItemType itemType, String fieldType) {
                      if("myField".equals(fieldName)){
                          SelectItem item = new SelectItem();
                          Map<String,String> valueMap = new HashMap<>();
                          valueMap.put("1", "val 1");
                          valueMap.put("2", "val2 2");
                          item.setValueMap(valueMap);
                          return item;
                      }
                      return super.getValueFieldProperties(type, fieldName, operatorId, itemType, fieldType);
                  }
              };
      But it still not working.
      I guess this is about displayField because on selection any option I get the ID on screen. I tried to set displayField on primaryKey field but still its not showing data on screen.
      Can you please tell if I am doing it wrong. Also I want to pass criteria in these fields fetch calls.

      Thanks in advance.
      Last edited by preeti_kanyal; 17 Jun 2019, 00:02.

      Comment


        #4
        You are able to provide any SelectItem properties you want, so you can pass optionCriteria or provide a pickListCriteriaFunction, or setPickListFields if there’s some other field you wish to use rather than the PK.

        Setting the displayFirld also works as usual, so something is likely wrong in your code. There are no obvious errors in the small amount of code you’ve shown, we would need complete, ready-to-run code in order to pin down the error.

        Comment


          #5
          Hi Isomorphic ,

          Setting any property on the selectitem is not working.
          The datasource field values are fetched from another data source. How do I tell FilterBuilder that for X datasource the display value is Y property of X Datasource. I tried doing the below but no success:
          Code:
           filterBuilder = new FilterBuilder() {
          
                      @Override
                      public FormItem getValueFieldProperties(FieldType type, String fieldName, OperatorId operatorId, ValueItemType itemType, String fieldType) {
                          if ("style".equals(fieldName)) {
                              SelectItem selectItem = new SelectItem();
                              selectItem.setDisplayField("myDisplayField");
                              selectItem.setValueField("myValueField");
                              return selectItem;
                          }
                          return super.getValueFieldProperties(type, fieldName, operatorId, itemType, fieldType);
                      }
                  };
          filterBuilder.setDataSource(DataSource.get("MyDS"));
          
          
          <DataSource ID="MyDS"
                      serverType="hibernate"
                      beanClassName="com.MyClass"
                      configBean="sessionFactory"
                      autoDeriveSchema="false"
                      dropExtraFields="true">
              <fields>
                  <field name="id" type="integer" primaryKey="true" hidden="true"/>
                  <field name="field1" type="text" includeFrom="AnotherDS.someProperty" includeVia="test" hidden="true"/>
          
                  <field name="test" type="integer" foreignKey="AnotherDS.primaryKeyId" displayField="someProperty"/>
              </fields>
          </DataSource>
          Please suggest.

          Comment


            #6
            We're not sure why you'd expect that code to do something as the valueField and displayField settings don't line up with the fields... so it should be obvious that won't work.

            To reiterate, this is just standard SelectItem usage, it just happens to be in a FilterBuilder. If you have a SelectItem working *at all* with this DataSource you should be able to just replicate the configuration used for a normal SelectItem.

            You also need to be taking *really basic* troubleshooting steps like looking at the request and response, and using pickListFields, if necessary, as we've already suggested.

            Please don't ask support for help again until you've done the bare minimum that is required on your end - it's very inappropriate, as support is here to help with product issues, and there's not even a hint of one here.

            Comment


              #7
              Hi Isomorphic ,
              Apologies for giving very abstract information. Through I solved the issue. There was an include via defined on my field , So in getValueFieldProperties method I was getting the name of includevia field.
              Code:
                      <field name="myFieldName" type="text" includeFrom="XYZ.name" includeVia="test" hidden="true"/>
              Now I wrote the below to solve the issue :
              Code:
                @Override
                          public FormItem getValueFieldProperties(FieldType type, String fieldName, OperatorId operatorId, ValueItemType itemType, String fieldType) {
                              switch (fieldName) {
                                  case "test":
                                      return getMyDropDown(fieldName);
              //other code here
                                       default:
                                      return super.getValueFieldProperties(type, fieldName, operatorId, itemType, fieldType);
                              }
                          }

              Can you please tell me is it possible to provide a datasource while overriding the above method?

              My DS entries looks like below :
              Code:
                      <field name="fieldName" type="text" includeFrom="SomeDS.value" includeVia="test" hidden="true"/>
                              <field name="test" type="integer" foreignKey="SomeDS.someId" displayField="TestField" title="myTitle"/>
              My overridden method is :

              Code:
              @Override
                          public FormItem getValueFieldProperties(FieldType type, String fieldName, OperatorId operatorId, ValueItemType itemType, String fieldType) {
                              switch (fieldName) {
                                  case "test":
                                      final SelectItem item = new  SelectItem();
               item.setDataSource(DataSource.get("NewDS"));
                              item.setAutoFetchData(true);
                              return item;
              
                                       default:
                                      return super.getValueFieldProperties(type, fieldName, operatorId, itemType, fieldType);
                              }
                          }
              The above code always sends a fetch of "SomeDS" not "NewDS". Can you please suggest how can we do this?
              Last edited by preeti_kanyal; 12 Jul 2019, 05:38.

              Comment


                #8
                .

                Comment


                  #9
                  Your code above should not compile as there is no setDataSource() API. But there is a setOptionDataSource() API which will do what you want.

                  Comment

                  Working...
                  X