Announcement

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

    ListGrid.refreshFields doesn't invoke showIf condition

    Hi,

    I use a ListGridField.setShowIfCondition method. This method gets evaluated when drawn.

    But when I call grid.refreshFields(); the method ListGridFieldIfFunction.execute doesn't get called and the listGrid shows all fields.

    I use oficial release of smartGWT 2.5
    best regards,
    Zdary

    #2
    By design, if you have made an explicit call to showField or hideField, or if the user has shown or hidden the field, the showIf expression is removed. If you think this is happening without this, please show a test case we can run.

    Comment


      #3
      I too am having an issue with refreshFields. I have a gridlist with a field:
      Code:
      name="policy_id" type="integer" required="true" optionDataSource="policy" displayField="policy_name"
      The list field "policy_id" renders the names ("policy_name") correctly until I call these lines:

      Code:
      	list.getField("endBeforeDate").setHidden( true );
      	list.refreshFields();
      At which point field "policy_id" renders the id, not the associated name.

      Really, what I'm trying to do is get the field "endBeforeDate" to hide (in an if statement), but it won't unless I call list.refreshFields() afterwards. Is there a better way to do this?
      Last edited by bootz15; 29 Sep 2011, 12:30.

      Comment


        #4
        Can you clarify what is wrong with calling refreshFields()?

        Comment


          #5
          Sure. Calling list.refreshFields() makes the "policy_id" field forget/lose its optionDataSource and/or displayName properties. Thus, in my example, it causes the policy ID value to be displayed, instead of the associated policy NAME value.

          Comment


            #6
            That doesn't seem to be a side-effect of refreshFields() - possibly you are also calling setFields() in some related code that is triggered at the same time?

            Comment


              #7
              No, not possible -- I do not call list.setFields() anywhere. I purposefully avoid setFields() because I have found that those new ListGridField's do not inherit attributes (like optionDataSource) from the existing DataSource fields; so then I have to specify those attributes again on the new fields which is utterly redundant code.

              So instead, I always try to use list.getField() and modify the existing field, not replace it. This is my preferred way... except that list.getField().setHidden(true/false) does not render in the UI until I call list.refreshFields(), which then causes my other rendering problems... you see the line of frustration that I'm experiencing now :)

              I am using smartgwtpower-3.0.

              Note that in the meantime, just to get it working, I _am_ writing the redundant code by instantiating new ListGridFields, setting attributes (like optionDataSource), and passing them list.setFields(). But I really don't want to do it this way.
              Last edited by bootz15; 3 Oct 2011, 06:40.

              Comment


                #8
                Unless we're misunderstanding something, refreshFields() should not be causing attributes such as optionDataSource to be dropped.

                Here's a very simple example showing this. If refreshFields() invalidated the optionDataSource setting we'd expect the displayed value to go from the display value "dos" in the live grid to the data value "two". Not what we're seeing.

                Code:
                  @Override
                    public void onModuleLoad() {
                        
                        DataSource testDS = new DataSource();
                        testDS.setClientOnly(true);
                        
                        DataSourceField f1 = new DataSourceField("f1", FieldType.TEXT);
                        DataSourceField f2 = new DataSourceField("f2", FieldType.TEXT);
                        
                        testDS.setFields(f1,f2);
                        
                        ListGridRecord r1 = new ListGridRecord();
                        r1.setAttribute("f1", "one");
                        r1.setAttribute("f2", "uno");
                        
                        ListGridRecord r2 = new ListGridRecord();
                        r2.setAttribute("f1", "two");
                        r2.setAttribute("f2", "dos");
                        
                        testDS.setTestData(new Record[] {r1,r2});
                        
                        
                        final ListGrid grid = new ListGrid();
                        ListGridField gridField = new ListGridField();
                        gridField.setOptionDataSource(testDS);
                        gridField.setName("x");
                        gridField.setValueField("f1");
                        gridField.setDisplayField("f2");
                        
                        grid.setFields(gridField);
                        grid.setData(new ListGridRecord[] {new ListGridRecord() {{ setAttribute("x", "two"); }}});
                        
                        grid.draw();
                        
                        Button refreshFields = new Button();
                        refreshFields.setLeft(400);
                        refreshFields.setTitle("Refresh Fields");
                        refreshFields.addClickHandler(new ClickHandler() {
                            
                            @Override
                            public void onClick(ClickEvent event) {
                                grid.refreshFields();
                                
                            }
                        });
                        
                        refreshFields.draw();
                    }
                See if you can tweak this sample code, or show us something similarly simple based on your use case that demonstrates the bug for us.

                Thanks
                Isomorphic Software

                Comment

                Working...
                X