Announcement

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

    Dynamically Setting The Selected Record Of A ComboBoxItem

    I've got a ComboBoxItem which is bound to a dataSource. I'd like to be able to iterate over all of the items in the list (similar to ListGrid.getRecords()) but I don't see that it is possible.
    Is that correct that it is not possible to iterate over the list of items in a ComboBoxItem to select a specific record (not based on the value).

    I do not want to do a ComboBoxItem.setValue("..") because I'm choosing the record based on a different field.

    #2
    I'm guessing that by the lack of responses that this is not possible. That's a shame, it seems like a pretty basic feature that is needed.

    Comment


      #3
      Another and better theory for the lack of responses is explained in the FAQ: no one understands the point of doing this (Isomorphic or the community).

      Comment


        #4
        Originally posted by Isomorphic
        Another and better theory for the lack of responses is explained in the FAQ: no one understands the point of doing this (Isomorphic or the community).

        Am I to understand that Isomorphic doesn't understand the point of being able to iterate over the items in a combox?

        Is there a different way to access the ListGridRecords of a combobox so one could be selected dynamically? I could not find any mention of it in the documentation.

        Comment


          #5
          There are multiple ways to do this. What we don't understand is what's wrong with the existing APIs - that's what you need to articulate to get attention from Isomorphic (see FAQ).

          Comment


            #6
            Originally posted by Isomorphic
            There are multiple ways to do this. What we don't understand is what's wrong with the existing APIs - that's what you need to articulate to get attention from Isomorphic (see FAQ).

            Could you point me to one of the ways of doing this?

            Let me try to better define what I'm trying to accomplish.

            A ComboBoxItem has a list of items. The pick List has three columns: Id, Name, Description. The Name is set as the Display Field, however it is not guaranteed to be unique. In the datasource Id is defined as a primary key, which is of course unique. Is it possible to select a specific item by the Id, which is not set as the DisplayField?

            Code:
            ComboBoxItem comboBox = new ComboBoxItem();
            comboBox.setOptionDataSource(dataSource);
            
            ListGridField id = new ListGridField("Id");
            ListGridField name = new ListGridField("Name");
            ListGridField description = new ListGridField("Description");
            
            comboBox.setPickListFields(id, name, description);
            comboBox.setFilterFields("Id", "Name", "Description");
            comboBox.setDisplayField("Name");
            
            ....
            // Somewhere else in code I'd like to be able to do dynamically
            // select a record by a provided Id.
            
            ...
            
            // If this were a ListGrid I would be able to iterate over the items and select
            // the record based on a attribute.
            
            ListGrid grid = new ListGrid();
            grid.setDataSource(dataSource);
            
            ListGridField id = new ListGridField("Id");
            ListGridField name = new ListGridField("Name");
            ListGridField description = new ListGridField("Description");
            
            grid.setFields(id, name, description);
            
            
            ...
            for (ListGridRecord record : grid.getRecords())
            {
               Integer id = record.getAttributeAsInt("Id");
               if ( id == suppliedId )
                   grid.selectRecord(record);
            }

            Comment


              #7
              setValue() changes the stored value and will derive the displayed value automatically. If you're not seeing this work, your field name must not be "Id" or you have not setValueField("Id").

              Comment


                #8
                Originally posted by Isomorphic
                setValue() changes the stored value and will derive the displayed value automatically. If you're not seeing this work, your field name must not be "Id" or you have not setValueField("Id").

                Ok, so I just want to summarize this thread, so that I am understanding things correctly.

                1) It is possible to select an item by calling setValue() as long as you have defined which column is the value by setValueField().

                3) It is not possible to iterate over the list of items in a ComboBoxItem list

                3) It is not possible to select an item by a value that is not the display name or the value (some other ListGridColumn)

                Comment


                  #9
                  1. Right

                  2&3 Wrong (DataArrived)

                  Comment


                    #10
                    Originally posted by Isomorphic
                    2&3 Wrong (DataArrived)

                    But outside of the DataArrived Event you cannot iterate over the already displayed list, correct?

                    Comment


                      #11
                      On the event you can get the dataset.

                      Comment


                        #12
                        Originally posted by Isomorphic
                        On the event you can get the dataset.
                        Ok. Just to put this out there, because from your direction, I'm not seeing a different way to do this.

                        Code:
                        ComboBoxItem comboBox = new ComboBoxItem();
                        
                        ...
                        
                        Record[] dataGridRecords = new Record[0];
                        
                        comboBox.addDataArrivedHandler(new DataArrivedHandler() 
                        {
                        
                        	@Override
                        	public void onDataArrived(DataArrivedEvent event)
                        	{
                        		dataGridRecords =event.getData().toArray();
                                }
                        });
                        
                        ...
                        
                        public void setRecordFromAttributeValue(String desiredAttribute)
                        {
                         	for(Record record : dataGridRecords)
                        	{
                        		String attribute = record.getAttribute("AttributeName");
                        		if(attribute.equals(desiredAttribute))
                        		{
                        			Integer id = record.getAttributeAsInt("Id");
                        			comboBox.setValue(id);
                        			return;
                        		}
                        	}
                        	
                        }

                        Comment


                          #13
                          That works but there's no reason to convert to a Record[], that loses many useful methods on ResultSet (eg RecordList.find() variations).

                          Comment

                          Working...
                          X