Announcement

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

    ListGridField with optionDataSource shows value, not displayField

    I've run into this problem before but never got to the bottom of it. I have a ListGridField with an optionDataSource. When the grid is displayed the value is displayed without mapping to the displayValue.

    If I attempt to edit a record the SelectItem appears with the correct displayValue selected so I know the optionDataSource mapping is correct. But when I end editing on the row it goes back to displaying the value instead of the displayValue.

    SmartClient Version: SC_SNAPSHOT-2012-03-15_v8.2p/PowerEdition Deployment (built 2012-03-15)

    #2
    ListGridField.optionDataSource causes an immediate fetch of all records of the optionDataSource. To start troubleshooting, look at the results of that fetch, the valueField and displayField settings, and the data values in the ListGridRecords for that field.

    Comment


      #3
      Exactly when is that fetch done? When the grid is drawn?

      Is there any way to trigger that fetch or have it re-fetch in case the underlying data has changed?

      In my case I need to dynically determine the optionDataSource. Can I do that after the grid has been created and just use getField("myField").setOptionDataSource(newDS)? Or do I need to destroy the grid and recreate it in order to change it?

      Comment


        #4
        Yes, fetched on grid draw. No, not currently possible to force a re-fetch or dynamically set optionDataSource. It's a very simple feature because it's not typically used; it only works for small data volumes as the docs indicate. For something more dynamic but still small, you could derive a valueMap from a manual DataSource fetch, and setValueMap() works.

        Comment


          #5
          Thanks. I'll go with the valueMap approach.

          Comment


            #6
            Using setValueMap() works perfectly for me and makes the SelectItem a lot snappier too, even though the optionDataSource was cached.

            One follow on question. I don't find an api for getValueMap(). Is there any way access the valueMap. I need to create a copy of the ListGridField to add to a form as a FormItem and I need to carry the same valueMap across to the FormItem. Is there a way to get the value map for a ListGridField?

            Comment


              #7
              This is an oversight, but getAttributeAsJavaScriptObject() will get it, then the property names are the stored values and the values are the display values.

              Comment


                #8
                Thanks!

                getAttributeAsMap("valueMap") seems to work as well and can be passed directly into setValueMap().

                Comment

                Working...
                X