Announcement

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

    ListGrid reorderFields doesn't reorder all fields.

    SmartGWT Version: v8.2p_2012-08-06/LGPL Development Only (built 2012-08-06)
    IE9 dev mode

    I have a ListGrid that is bound to a DataSource and is reusing all DataSource fields. The DataSource is used by multiple components, so we have a need to reorder and rename the fields on the ListGrid. As such, we have made arrays containing all of the field names in their correct order. We then loop through this array, moving and renaming fields like so:
    Code:
    public void reorderFields()
    {
    	for (int i = 0; i < FIELD_INDICIES.length; i++)
    	{
    		// Rename each field.
    		setFieldTitle(getFieldNum(FIELD_INDICIES[i]), FIELD_TITLES[i]);
    
    		// Reorder each field.
    		reorderField(getFieldNum(FIELD_INDICIES[i]), i);
    	}
    }
    However, there's a single field that refuses to move using this method. It happens to be what should be the first field on the grid. It DOES move if I manually tell it to (after doing the above loop) like this:
    Code:
    reorderField(getFieldNum(FIELD_INDICIES[0]), 0);
    But it does NOT move on our first iteration of the above loop for some reason.

    My guess is that we are running into some weird race condition where we call reorderField before SmartGWT is done actually moving all of the other fields around.

    Any ideas about how to solve this problem would be appreciated.

    Thanks,
    Brian

    #2
    Don't use this approach - instead provide an array of fields in the order you want when you first call setFields(0).

    Comment


      #3
      So that mean's we need to override every field from the DataSource manually then?

      Comment


        #4
        No - read the Data Binding chapter of the QuickStart Guide for details on how best to use fields in combination with a DataSource.

        Comment


          #5
          I have read the chapter and nowhere does it say that we don't have to override our DataSource fields.

          If we have setUseAllDataSourceFields set to false, then we need to manually override each DataSourceField with a ListGridField. If we have it set to true, then the DataSource's field order is used. Correct me if I'm wrong.

          It's not a huge deal, just not as easy as having a base class method and a list of Strings that we can loop through to automatically reorder and rename everything.

          Comment


            #6
            So again, you need to form an array of the fields and provide them in the order you want.

            You can use setUseAllDataSourceFields() with this strategy or not - it's just a matter of whether it's easier to suppress fields vs omit them.

            Since you're apparently using a bunch of reorderField() calls to get your order right now, this strategy is no more manual or less automatic than your current code, and it seems like the new code should be simpler to understand.

            Providing the desired order up front is also going to prevent useless work on the part of the grid. Currently, you are basically configuring the grid with the wrong order, then having it change configuration on the fly to reflect the order you actually wanted.

            Comment


              #7
              Originally posted by Isomorphic View Post
              So again, you need to form an array of the fields and provide them in the order you want.

              You can use setUseAllDataSourceFields() with this strategy or not - it's just a matter of whether it's easier to suppress fields vs omit them.

              Since you're apparently using a bunch of reorderField() calls to get your order right now, this strategy is no more manual or less automatic than your current code, and it seems like the new code should be simpler to understand.

              Providing the desired order up front is also going to prevent useless work on the part of the grid. Currently, you are basically configuring the grid with the wrong order, then having it change configuration on the fly to reflect the order you actually wanted.
              I suppose that's true.

              Where do we draw the line about how many fields we should reorder, though? If I'm just reordering one or two fields am I supposed to use reorderField, or do I need to override every field from the DataSource to just get those two fields where I want them?

              I am now hesitant to use reorderField knowing that it doesn't work right all the time.

              Thanks,
              Brian

              Comment


                #8
                Note we don't know of a bug in reorderField(), and we can't run your code to check.

                In general, if you are hand-specifying fields, use whatever is shortest.

                If you're doing something programmatic (like maybe you have some additional metadata stored somewhere that affects field order), then "overriding every field in the DataSource" is not a big thing. It's a very simple for() loop to create one ListGridField per DataSourceField - remember, you only need to specify name.

                Comment


                  #9
                  Is it by design that ListGridFields do not inherit their corresponding DataSourceFields' "displayField" attributes?

                  I've found that for DataSourceFields where I have the "displayField" attribute set (as described here) that I need to re-specify it on the ListGridField, even if the name and title of the ListGridField matches.

                  Thanks for all your feedback, Isomorphic, you're the best!
                  Brian

                  Comment


                    #10
                    "displayField" doesn't exist as a property on DataSourceField - so yes.

                    Comment

                    Working...
                    X