Announcement

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

    ComboBoxItem TextMatch Filter not work after pickList apply

    I use SmartGWT Power Edition and version "SmartClient Version: v9.1p_2014-03-04/PowerEdition Deployment (built 2014-03-04)"
    And Firebox "ESR 24.3.0"

    and I have a case as following
    There are two fields "categoryItem" and "itemName" and when change the category value, the pickList of itemName will change accordingly (just like the example http://www.smartclient.com/smartgwt/showcase/#form_dep_db_dep_selects)
    But one more requirement that after the "itemName" field pick list change based on the selection of "categoryItem", we also want to have TextMatch filter so that when the user type in text value on "itemName", it can further filter based on the depending pick list.

    However, based on the code shown below, I find that when I input some text value in itemName, it cannot perform any further filter based on the PickList, so I have a very simple example code that is runnable as below, can you advice any issue on the code? how can I change so that I can further filter the pick list (that is already firstly filtered by value of categoryItem)?

    Code:
    import com.google.gwt.event.shared.EventBus;
    import com.google.inject.Inject;
    import com.smartgwt.client.data.Criteria;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.types.TextMatchStyle;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.layout.HLayout;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class DependencyFilter1Panel extends HLayout {
    
    
    	private final EventBus eventBus;
    	
    	@Inject
    	public DependencyFilter1Panel(final EventBus eventBus) {
    		setSize("100%", "100%");
    		this.eventBus = eventBus;
    		final VLayout vLayout = new VLayout();
    		ScrollToMainToolBar mainToolStrip = new ScrollToMainToolBar(this.eventBus);
    		vLayout.addMember(mainToolStrip);
    		
    		final VLayout vLayout1 = new VLayout();
    		vLayout1.setOverflow(Overflow.SCROLL);
    		
            final DynamicForm form = new DynamicForm();  
            form.setWidth(500);  
            form.setNumCols(4);  
      
            DataSource itemSupplyDS = ItemSupplyXmlDS.getInstance();  
            DataSource supplyCategoryDS = SupplyCategoryXmlDS.getInstance();  
      
            final SelectItem categoryItem = new SelectItem();  
            categoryItem.setName("categoryName");  
            categoryItem.setPickListWidth(210);  
            categoryItem.setTitle("Category");  
            categoryItem.setOptionDataSource(supplyCategoryDS);  
      
            categoryItem.addChangedHandler(new ChangedHandler() {  
                public void onChanged(ChangedEvent event) {  
                    form.clearValue("itemName");  
                }  
            });  
      
    		final ListGridField itemField = new ListGridField("itemName");
    		final ListGridField unitsField = new ListGridField("units");
    		final ListGridField description = new ListGridField("description");		        
            
    		
    		
            ComboBoxItem itemName = new ComboBoxItem() {  
                @Override  
                protected Criteria getPickListFilterCriteria() {  
                    String category = (String) categoryItem.getValue();  
                    Criteria criteria = new Criteria("category", category);  
                    return criteria;  
                }  
            };  
            itemName.setName("itemName");  
            itemName.setTitle("Item");  
            itemName.setPickListWidth(250);
            itemName.setAutoFetchData(true);
            itemName.setOptionDataSource(itemSupplyDS); 
            itemName.setFilterFields("itemName", "description", "units");
            itemName.setTextMatchStyle(TextMatchStyle.SUBSTRING);
            itemName.setValueField("SKU");
            itemName.setDisplayField("itemName");
            itemName.setPickListWidth(450);
            itemName.setPickListFields(itemField, description, unitsField);
            form.setItems(categoryItem, itemName);  
    		vLayout.addMember(form);
    		addMember(vLayout);
    	}
    		
    }

    #2
    Your implementation of getPickListFilterCriteria ignores the user-entered value, which can be retrieved via getEnteredValue(). You should return criteria that use both the categoryName and the user-entered value (as a search string for the itemName field).

    Comment


      #3
      thx Isomorphic

      Per advice and have following change and find both filtering work...

      Code:
             final ComboBoxItem itemName = new ComboBoxItem() {  
                  @Override  
                  protected Criteria getPickListFilterCriteria() {  
      				String category = (String) categoryItem.getValue();
      				String itemNameValue = (String)getEnteredValue();
      				SC.logInfo("category:" + category);
      				SC.logInfo("itemNameValue:" + itemNameValue);
      				Criteria criteria;
      				if ( itemNameValue != null && !"".equals(itemNameValue) ) {
      					SC.logInfo("itemNameValue not null");
      					criteria = new AdvancedCriteria(OperatorId.AND, new Criterion[]{
          						new Criterion("category", OperatorId.EQUALS, category),
                  				new AdvancedCriteria(OperatorId.OR, new Criterion[]{
                  						new Criterion("itemName", OperatorId.ICONTAINS, itemNameValue ),
                  						new Criterion("description", OperatorId.ICONTAINS, itemNameValue ),
                  						new Criterion("units", OperatorId.ICONTAINS, itemNameValue )
                  				})
                  		});
      				} else {
      					SC.logInfo("itemNameValue is null");
      					criteria = new Criteria("category", category);
      				}
      				return criteria;
                  	
                  }  
              };

      Comment

      Working...
      X