Announcement

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

    SelectItems - Multiple Selections & Filters

    Hey,

    I played around with the multiple selections of the SelectItem and I guess I found a bug. I attached my sample code and tested the following case.

    1. Click on the SelectItem to open the subgrid.
    2. Select the first 2 records... they will appear in the Item as selected.
    3. Then use the filter of the column "Name" and enter 99
    4. Choose the record with is filtered.
    5. The 2 records you selected first are not selected anymore and only "name 99" appears as selected

    So basically this means that you can not use the filter for those kind of fields.

    Thanks
    Andy




    Setup:
    SmartGWT Version 12.1 latest nightly LGPL & Version 12.1 latest nightly LGPL
    GWT: 2.8.2
    Browser: latest Chrome

    Code:
    import java.util.ArrayList;
    import java.util.List;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.types.DSDataFormat;
    import com.smartgwt.client.types.MultipleAppearance;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.uds.webadmin.client.data.CSourceFields;
    
    public class GTestForm
    {
    
        public GTestForm()
        {
            initForm();
        }
    
        public void initForm()
        {
            // create form
            final DynamicForm form = new DynamicForm();
            form.setWidth( 300 );
    
            // Create selectItem
            SelectItem item = new SelectItem( "itemID" );
            item.setOptionDataSource( getDataSource() );
            item.setWidth( 240 );
            item.setTitle( "Item" );
            item.setPickListWidth( 450 );
            item.setPickListFields();
            item.setValueField( "ID" );
            item.setDisplayField( "Name" );
            item.setPickListWidth( 450 );
            item.setMultiple( true );
            item.setMultipleValueSeparator( "," );
            item.setShowDeletions( false );
            item.setMultipleAppearance( MultipleAppearance.PICKLIST );
    
            // create subgrid fields
            ListGridField idField = new ListGridField( "ID" );
            ListGridField nameField = new ListGridField( "Name" );
            ListGridField descriptionField = new ListGridField( "Description" );
    
            // create Grid
            final ListGrid listGrid = new ListGrid();
            listGrid.setShowFilterEditor( true );
            listGrid.setEmptyCellValue( "---" );
    
            // assign Grid & fields
            item.setPickListProperties( listGrid );
            item.setPickListFields( idField, nameField, descriptionField );
    
            form.setItems( item );
    
            form.draw();
        }
    
        private DataSource getDataSource()
        {
            // New DataSource
            DataSource ds = new DataSource();
            ds.setID( "TestDS" );
            ds.setClientOnly( true );
    
            // Create fields
            DataSourceIntegerField idField = new DataSourceIntegerField( "ID", "ID" );
            idField.setPrimaryKey( true );
            DataSourceTextField nameField = CSourceFields.getTextField( "Name", "Name" );
            DataSourceTextField descriptionField = CSourceFields.getTextField( "Description", "Description" );
    
            // Assign Fields
            ds.setFields( idField, nameField, descriptionField );
    
            // Add records to DS
            List<Record> resultList = getRecords( 100 );
            for ( Record record : resultList )
            {
                ds.addData( record );
            }
    
            return ds;
        }
    
        private List<Record> getRecords( int numbers )
        {
            List<Record> resultList = new ArrayList<Record>();
            for ( int i = 0; i < numbers; i++ )
            {
                // Create new record
                Record record = new Record();
                record.setAttribute( "ID", ( i + 1 ) );
                record.setAttribute( "Name", "Test Name" + ( i + 1 ) );
                record.setAttribute( "Description", "Test Description" + ( i + 1 ) );
    
                // Add record
                resultList.add( record );
            }
    
            return resultList;
        }
    }

    #2
    Please see your Developer Console - you should see a warning telling you that this is not a valid combination of properties, pointing you to the pickListProperties docs, which explain:

    Setting showFilterEditor:true in SelectItem.pickListProperties is a valid way to create a filterable pickList, on a SelectItem, but this setting is not supported on a SelectItem with SelectItem.multiple set to true - this combination of settings can cause a selected value to be filtered out of view at which point further selection changes will discard that value.
    In general we recommend the ComboBoxItem class (with ComboBoxItem.addUnknownValues set as appropriate) as a better interface for filtering pickList data.

    Comment


      #3
      Thanks... I understand. And thanks for pointing this out! I did not saw this

      Comment

      Working...
      X