Announcement

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

    ListGrid Defined in DataSource Descriptor with Several Dependent Selects

    SmartClient Version: v10.1p_2016-12-11/Enterprise Deployment (built 2016-12-11)
    Chrome Version 64.0.3282.167

    I'm running into an issue with a ListGrid I'm building. The grid is defined in a ds.xml descriptor, and several of the columns have foreignKey/includeFrom relationships, so their values are automatically fetched from their external ds.xml files. All my fetch, add, update, and remove operations are tied to EJB methods on the server for creation, deletion, etc. All of the foreignKey relationships work and display SelectItems, but I'm wanting some of the fields to be dependent on selections in other fields.

    I've tried following both examples of Dependent Selects in the Showcase, but neither really got me what I was looking for because one of them defines the values for it's fields from static maps, and the other uses DynamicForm. I have a dependent relationship setup between 2 columns currently that I've been tinkering with. I have a ChangedHandler assigned to column 1 where the onChanged method takes the key for the selected object in column 1 and assigns it as optionCriteria for column 2. If I click away from the entire ListGridRecord (so that the edited value shows blue edit text), I can click on column 2 and get the desired results from that fields fetch. What I'd LIKE is to not have to click out of the record every time I make a change in one of the columns.

    Here is the code from my grid's constructor:
    Code:
            this.setWidth100();
            this.setHeight("40%");
            this.setDrawAheadRatio(4);
            this.setShowFilterEditor(false);
            this.setCanSelectCells(false);
            this.setSelectOnEdit(true);
    
            this.addDrawHandler(event -> {
                final ListGridField fieldOne = this.getField("parentKey");
                final ListGridField fieldTwo= this.getField("childKey");
    
               fieldOne.addChangedHandler(new ChangedHandler()
                {
                    @Override
                    public void onChanged(ChangedEvent event)
                    {
                        Integer parentKey = (Integer) event.getValue();
                        Criteria criteria = new Criteria();
                        criteria.addCriteria("parentKey", parentKey);
                        fieldTwo.setOptionCriteria(criteria);
                    }
                });
            });
    Is there some way I can force fieldTwo to automatically fetch with the new criteria when fieldOne is chanegd without having to click away from the record every time? Please let me know if I need to provide more information or clarify anything.
    Last edited by Pro-crastinator; 3 Apr 2018, 04:32.

    #2
    There's a second Dependent Selects example that shows how to correctly do this with grids. It shows a pickListCriteria function that pulls data from related fields to form criteria - this will avoid the problem you're currently having with trying to change optionCriteria on the fly.

    Comment


      #3
      Originally posted by Isomorphic View Post
      There's a second Dependent Selects example that shows how to correctly do this with grids. It shows a pickListCriteria function that pulls data from related fields to form criteria - this will avoid the problem you're currently having with trying to change optionCriteria on the fly.
      I'm not sure how I overlooked the fact that there were two separate examples within the Dependent Selects (Grids), but thank you for pointing it out to me because the second (Remote Data) resolved my issue. Thanks for your help!

      Comment


        #4
        I'm bringing this thread back to life with another, similar question.

        I'm trying to make the same approach work within the expansion component of a ListGrid. The ListGrid fields are still defined in a ds.xml file as before, but now the dependent selects are fields that are only visible within the expansion component (detail="true"). Instead of using ListGridFields, I tried this with FormItems as is done in the Dependent Selects (DataBound) example since I'm now doing this within a DynamicForm. Similar to the grid example, I set a ChangeHandler that "resets" my "child" field when the "parent" field value is changed. This part works correctly:

        Code:
        final FormItem parent = form.getField("parentKey");
        
        parent.addChangedHandler(new ChangedHandler()
        {
            @Override
            public void onChanged(ChangedEvent event)
            {
                 form.setValue("childKey", (String) null);
            }
        });
        However, when I click on the "child" field, no fetch is ever triggered because it seems that the field doesn't recognize that setPickListFilterCriteriaFunction has been set on the SelectItem I created for it:

        Code:
        form.addDrawHandler(event -> {
        
        final FormItem child = form.getField("childKey");
        SelectItem select = new SelectItem();
        
        select.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction()
        {
        
            @Override
            public Criteria getCriteria(FormItemFunctionContext itemContext)
            {
                Integer pKey = (Integer) parent.getValue();
                Criteria criteria = new Criteria();
                criteria.addCriteria("pKey", pKey);
                return criteria;
            }
        });
        
        select.setValueField("key");
        select.setDisplayField("name");
        child.setEditorProperties(select);
        });
        Note that "key" and "name" are fields in the ds.xml that the child field has it's foreignKey/includeFrom relationship with.

        Is there some other approach I should be following to make this work within an expansion component? I'd hoped this would be as straightforward as the Grid example was, but so far that hasn't been the case for me.

        EDIT: After posting this I discovered a solution that works, so I'll include it here in case someone else comes along and needs help on this topic:

        Rather than defining the separate SelectItem and setting it as the editor for the "child" field, I got the "child" field directly from the form AS a SelectItem like so:


        Code:
        final SelectItem child = (SelectItem) form.getField("childKey");
        
        child.setPickListFilterCriteriaFunction(new FormItemCriteriaFunction()
        {
            @Override
            public Criteria getCriteria(FormItemFunctionContext itemContext)
            {
                Integer pKey = (Integer) parent.getValue();
                Criteria criteria = new Criteria();
                criteria.addCriteria("pKey", pKey);
                return criteria;
            }
        });
        Note that "pKey" is the parameter my backend processing logic is looking for.

        This immediately resolved the issue. I hope this helps someone else along the way!
        Last edited by Pro-crastinator; 4 Jun 2018, 10:40. Reason: Figured out the solution immediately after posting.

        Comment

        Working...
        X