Announcement

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

    SelectItem with Record Display - or Display multiple fields for a choice selection.

    SmartClient Version: v12.1p_2021-10-22/PowerEdition Deployment (built 2021-10-22)

    I have a SelectItem, and like in your example: https://www.smartclient.com/smartgwt...#selectlist_ms I want the select list to be more than a single field value. The user wants to see several fields in order to pick the correct single choice.

    Code:
           refRunSelector = new SelectItem();
    
      //     refRunSelector.setOptionDataSource("Run_Names");     ???
    
            ListGridField nameField = new ListGridField("Name","Run Name");
            nameField.setType( ListGridFieldType.TEXT );
            ListGridField predictedField = new ListGridField("PredictedResults", "Predicted  Result");
            predictedField.setType( ListGridFieldType.TEXT );
            refRunSelector.setPickListFields(nameField, predictedField);
            refRunSelector.setDisplayField("Name");
            refRunSelector.setValueField("PK_Run_Name");
    I don't want to automatically fetch the data from a DataSource (Run_Names), but I do want to set the fields of the SelectItem to display the "Name" and "PredictedResults" fields.

    I have the data I want to put in the selector already, as a RecordList.

    The difficulty is that I only see a refRunSelector.setValues ( Map ) call, and I really want to do a

    refRunSelector.setData( Record[] foo) ;

    call, or one of the forms of a ListGrid.setData().

    What is the appropriate way to do this, or am I on completely the wrong track?
    Last edited by tece321; 4 Nov 2021, 13:55. Reason: Typo

    #2
    The value of a SelectItem with an optionDataSource is the value of the PK value for the selected record. Just assign that PK record as the value and the SelectItem automatically fetches the complete record (including from cache, if it’s already there).

    See fetchMissingValues if you want more details.

    Comment


      #3
      Hi tece321,

      I'm not sure this is the best option, but you could use your Record[] foo to build a clientOnly-DataSource from it and set the data via setCacheData(Record... cacheData).
      This way you don't have the server hit, but also multiple fields.

      Best regards
      Blama

      Comment


        #4
        @Blama,

        Yes the SmartGWT showcase example of a SelectItem shows how to use a clientOnly DataSource, and setting the cached data will probably work. But I was looking for a more direct way, as I suggested a way to set a Record[] foo into the SelectItem. In the end I may have to follow your suggestion.

        Isomorphic
        Thanks for the reply. My goal is not to use the optionDataSource to force fetches, as the app has already fetched that data, and I just want to extract more than one field from that data and use it to display in the SelectItem. What do you mean by "Just assign that PK record as the value". Do you mean this line of code

        refRunSelector.setValueField("PK_Run_Name") ?

        Fine, am trying to understand a way of setting the records in the SelectItem of fields of a Recod like this: { "PK_Run_Name", "Name", "PredictedResult"}.

        I looked at fetchMissingValues, and it seems to imply reading from the cached data or causing a fetch (which I don't want to happen).

        The original DataSource "Run_Names", has many more fields than those three listed above. Can I assume the SelectItem will just extract the setValueField, and the setPickListFields from the data associated or cached earlier with the original data fetch? Is that what you are saying?

        Thanks

        Comment


          #5
          Not setValueField(), setValue(pkValue).

          If you already have all of the data loaded and in a clientOnly DataSource, then the fetch is within the browser, so not an issue presumably.

          Comment


            #6
            @Isomorhic

            Not setValueField(), setValue(pkValue).


            That just doesn't make sense to me. I'm trying to fill the selector select list with an array of "records" for a choice by the user. What has setting a single value of the valueField got to do with that?

            Or

            Are you saying that setting the optionDataSource on the SelectItem will simply fill the selection choices from the already fetched data - and the setValueField (pkValue) is setting the choice by the user?



            Comment


              #7
              What has setting a single value of the valueField got to do with that?
              You are not setting "a single value of the valueField". The valueField is singular - one atomic value like a String or integer.

              So again, the value of a SelectItem with an optionDataSource - what it stores in form.values - is the PK value from the selected record. Just the PK value, not the whole record.

              This matches how SQL (and almost all other databases) work - when a record is related to another record, it stores the ID of that record, and only the ID.

              The pkValue you set as the value of the SelectItem - again with selectItem.setValue(pkValue) - then allows the SelectItem to look up that record in it's optionDataSource.

              If the optionDataSource is a clientOnly DataSource, that won't be a server fetch, just a fetch for the record from already cached data. Which is what you've asked for.

              Comment


                #8
                Not sure exactly how we got on to a the sidebar of talking about the setValue() in this case. I was just concerned with allowing the SelectItem display a number of fields, rather than a single selector field, when pulled down. The setValue() discussion didn't help or really pertain (imho) to this thread.

                The simple answer is that in this instance one MUST use an Option DataSource for the SelectItem and specify the PickListFields. One cannot just setData( Record []) on the SelectItem.

                Yes if the data is already fetched and cached in the browser, it will not be fetched a second time.

                Simply replying that a setData( Record []) on a Form Item is not allowed, and one must use a DataSource, (Option DS in this case) was what I was looking for originally.

                Comment


                  #9
                  Sorry, it looks like both we and Blama assumed you had already understood that aspect, as you posted code that used an optionDataSource and a sample that used pickListFields.

                  Anyway, once you are using an optionDataSource, setValue(pkValue) is how you cause a specific record to be the selected record.

                  Comment

                  Working...
                  X