Announcement

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

    How can I set destroyOnUnEmbed for an embedded component

    Hello,

    I create an embedded component via ListGrid.getExpansionComponent().

    How can I set destroyOnUnEmbed for this component?
    I want, that this component is automaticly destroyed when the component was closed.

    I'm using SmartGWT 5.0.

    Thank you

    Peter

    #2
    Override getExpansionComponent() and call Super to get the automatically generated component, then configure it as desired before returning it.

    Comment


      #3
      Hello,

      I don't know, if I understand you correctly.
      Is this that what you mean?

      Code:
          @Override
          protected Canvas getExpansionComponent(ListGridRecord record)
          {
              setExpansionMode(ExpansionMode.DETAIL_FIELD);
              Canvas component = super.getExpansionComponent(record);
              if (myComponent!= null)
              {
                  Canvas[] children = component.getChildren();
                  for (Canvas child : children)
                  {
                      component.removeChild(child);
                      child.destroy();
                  }
                  component.addChild(myComponent);
              }
      
              return component;
          }
      Peter

      Comment


        #4
        No - do only what we said above, no calls to destroy or iteration through children.

        Comment


          #5
          So, I don't understand what you mean. I want to create my own embedded component and I want, that it will be destroyed, when the record is collapsed.

          When I call super.getExpansionComponent(record), I get an Canvas with a content, that I don't want have.

          Please explain a little bit detailed.

          Peter

          Comment


            #6
            We're not sure what further we can explain..

            The behavior for use of expansionComponents is controlled by listGrid.expansionComponentPoolingMode. The default of "destroy" is already what you say you want. So you should not have to do anything and we don't know why you think you need to add additional settings.

            But if you were to try to set destroyOnUnEmbed, you'd need a setAttribute() call, and you don't seem to be attempting that at all - we don't understand what your code snippet was intended to accomplish.

            Comment


              #7
              The problem is in the function removeEmbeddedComponent :
              Code:
                  if (component.isExpansionComponent && this.grid.expansionComponentPoolingMode != "none") {
                      // this is an expansionLayout - the first (only) member is an expansionComponent
                      var exComp = component.members[0];
                      if (this.grid.expansionComponentPoolingMode == "destroy") {
                          // "destroy" pooling mode
                          if (!exComp.isStockComponent) {
                              // custom component - remove the custom component from the wrapper layout prior
                              // to destroying the layout - don't destroy the custom component,
                              // unless grid.destroyCustomExpansionComponents or comp.destroyOnUnembed
                              // have been set to true
                              if (!this.grid.destroyCustomExpansionComponents && !exComp.destroyOnUnembed) {
                                  component.removeMember(exComp);
                                  exComp.deparent();
                              }
                          }
                          component.destroy();
                      }
                  } else {
              By default
              isStockComponent is undefined,
              this.grid.destroyCustomExpansionComponents is false
              exComp.destroyOnUnembed is undefined

              I set now the attribut destroyCustomExpansionComponents to true by
              Code:
              setAttribute("destroyCustomExpansionComponents", true, true);
              and it works.

              Maybe you can make a method setDestroyCustomExpansionComponents in ListGrid.

              Thank you

              Peter

              Comment


                #8
                If you've got a custom component, just add a RecordCollapseHandler and destroy() there.

                Sometimes reading the source code can make you miss an obvious solution using documented APIs - watch out for that.

                Comment


                  #9
                  I have know add a RecordCollapseHandler
                  Code:
                          addRecordCollapseHandler(new RecordCollapseHandler()
                          {
                  
                              @Override
                              public void onRecordCollapse(RecordCollapseEvent event)
                              {
                                  Canvas component = getCurrentExpansionComponent(event.getRecord());
                                  if (component != null)
                                      component.destroy();
                              }
                  
                          });
                  When expansionComponentPoolingMode is "destroy", I get an exception because exComp == null in exComp.isStockComponent.
                  When expansionComponentPoolingMode is "none", the component, that is created around my empedded component, will be remove from ListGrid, but not destroyed. Correctly?

                  Comment


                    #10
                    I think, I have it now:
                    Code:
                            addRecordCollapseHandler(new RecordCollapseHandler()
                            {
                    
                                @Override
                                public void onRecordCollapse(RecordCollapseEvent event)
                                {
                                    ListGridRecord record = event.getRecord();
                                    Canvas component = getCurrentExpansionComponent(record);
                                    if (component != null)
                                    {
                                        removeEmbeddedComponent(record);
                                        component.destroy();
                                    }
                                }
                    
                            });
                    Thank you for your help and discussion.

                    Peter

                    Comment

                    Working...
                    X