Announcement

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

    TreeGrid, SelectionAppearance.CHECKBOX and loading some of the nodes as selected

    Hi,
    I'm a newcomer to this library, although I've been working with GWT for a year now, and it interests me a lot.
    I've searched the forums for an answer but could not find it so I decided to post:
    Assuming I'm using the CheckboxTree sample from the showcase, how can I programatically mark some of the nodes as selected on startup?
    The main use-case is where this checkbox tree represents some sort of viewing preferences of the user and I'm sending from the server a list of the relevant data which I parse into tree node. I'd like to use one of these properties to determine whether to mark a node's checkbox or not.

    Thanks in advance,
    Ittai

    #2
    Hi,
    Was this question out of line? As it is about the client-side functionality of smartGWT and I thought this is in the community side of support.
    I do hope someone has experience, even if that experience indicates what I want does not exist, with this isseu.

    Thanks,
    Ittai

    Comment


      #3
      We've recently exposed a new attribute for this.
      You'll need to get the latest SGWT build.
      Then check out the "selectionProperty" attribute of ListGrids and TreeGrids.
      This will allow you to specify a property directly on a ListGridRecord or TreeGrid node to mark the item as selected.

      Here's an example usage based on the TreeGrid / local data example from the showcase. Notice the lines setting up 'isSelected' as the selectionProperty on the TreeGrid and setting this property to true on one of the nodes:

      Code:
          public void onModuleLoad() {  
          	    TreeGrid treeGrid = new TreeGrid();  
          	         treeGrid.setWidth(300);  
          	         treeGrid.setHeight(400);  
          	   
          	         TreeGridField field = new TreeGridField("Name", "Tree from local data");  
          	         field.setCanSort(false);  
          	   
          	         treeGrid.setFields(field);  
          	   
          	         final Tree tree = new Tree();  
          	         tree.setModelType(TreeModelType.PARENT);  
          	         tree.setNameProperty("Name");  
          	         tree.setIdField("EmployeeId");  
          	         tree.setParentIdField("ReportsTo");  
          	         tree.setShowRoot(true);  
          	   
          	         
          	         EmployeeTreeNode root = new EmployeeTreeNode("4", "1", "Charles Madigen");  
          	         EmployeeTreeNode node2 = new EmployeeTreeNode("188", "4", "Rogine Leger");  
          	         
          	         EmployeeTreeNode node3 = new EmployeeTreeNode("189", "4", "Gene Porter");  
          	         EmployeeTreeNode node4 = new EmployeeTreeNode("265", "189", "Olivier Doucet");  
          	         EmployeeTreeNode node5 = new EmployeeTreeNode("264", "189", "Cheryl Pearson");  
          	         tree.setData(new TreeNode[]{root, node2, node3, node4, node5});  
          	   
          	         treeGrid.addDrawHandler(new DrawHandler() {  
          	             public void onDraw(DrawEvent event) {  
          	                 tree.openAll();  
          	             }  
          	         });  
          	           
          	         node2.setAttribute("isSelected", true);
          	         treeGrid.setSelectionProperty("isSelected");
          	         
          	         treeGrid.setData(tree);  
          	   
          	         treeGrid.draw();
          }
          public static class EmployeeTreeNode extends TreeNode {  
          	   
          	         public EmployeeTreeNode(String employeeId, String reportsTo, String name) {  
          	             setEmployeeId(employeeId);  
          	             setReportsTo(reportsTo);  
          	             setName(name);  
          	         }  
          	   
          	         public void setEmployeeId(String value) {  
          	             setAttribute("EmployeeId", value);  
          	         }  
          	   
          	         public void setReportsTo(String value) {  
          	             setAttribute("ReportsTo", value);  
          	         }  
          	   
          	         public void setName(String name) {  
          	             setAttribute("Name", name);  
          	         }  
          }

      Comment


        #4
        Hi,
        First of all thank you for your detailed response.
        If I mark node3 as selected (i.e. a node which has children) will they be recursively marked?
        And continuing the example you supplied will node1 be partially marked?
        My last question is if you can roughly estimate (of course with no guarantees) how stable is this build?

        Thank you very much in advance,
        Ittai

        Edit:
        I've downloaded the files from the link you supplied but sadly enough in both smartgwt.jar files (the one in the zip and the one out of it) I get the following message:
        "The method setSelectionProperty(String) is undefined for the type TreeGrid"
        Am I doing something wrong?
        Thank you
        Last edited by ittaiz; 26 May 2010, 05:36.

        Comment


          #5
          Hi,
          Has there been any news regarding this issue?
          I've entered the above link again but the last modified date is the same as of the day I downloaded.
          Is there a different location where I should look?

          Thanks,
          Ittai

          Comment


            #6
            @ISOMORPHIC

            hey hi..
            i download smartgwt jar from the link specified by u..
            but in treeGrid there is no setSelectionProperty(" ")..
            is there any such property added to smartGwt??
            And from where should i download the files so that i could get this property???
            i need to maintain the name of nodes corresponding to which checkbox are selected..

            is there any other solution for this?
            please help..!

            thanx!

            Comment


              #7
              Hi
              Same request here. I could also not find the setSelectionProperty() in the build from the location. Is there a different location where we need to take the build from. This feature is very much required for my project. Can anyone please help in this regard

              Thanks
              Kiran

              Comment


                #8
                I use the last build (06-Jul-2010) and the setSelectionProperty() method works.

                But, I have another pb : the name is not displayed beside the checkbox. The setName property of the treeNode is however filled by a non null string.

                Do you have any ideas about that ?

                Comment


                  #9
                  Just extends a TreeGrid like bellow:

                  Code:
                      private class ArvorePermissaoTreeGrid extends TreeGrid {
                          public ArvorePermissaoTreeGrid(ArvorePermissao arvorePermissao) {
                              super();
                              setSelectionAppearance(SelectionAppearance.CHECKBOX);
                              setShowPartialSelection(true);
                              setCascadeSelection(true);
                              setShowHeader(false);
                              setAttribute("selectionProperty", "isSelected", true); // TODO: futuros releases SGWT será substituído pelo método setSelectionProperty
                              addDrawHandler(new DrawHandler() {
                  
                                  @Override
                                  public void onDraw(DrawEvent event) {
                                      getTree().openAll();
                                  }
                              });
                              setData(arvorePermissao);
                          }
                      }
                  The setAttribute("selectionProperty"... does same thing of the 'last release' of setSelectionProperty, but this method is protected, needing to be extended to acess that attribute.
                  Last edited by ksfreitas; 3 Aug 2010, 18:35.

                  Comment


                    #10
                    I just made some tests to have some listgrid with SelectionAppearance.CHECKBOX with some rows selected from the begining, added dataArrivedHandler and use setSelectedState("valueField") and finally got it working.... but dont't know what happens now that I always get "valueField is not defined"... in firebug I can see that setSelectedState is call before listgrid is drawn, but I put setSelectedState, as I mentioned, on dataArrivedHandler, so teorically data must already been loaded.

                    setSelectedState is the most easy way to preselect some rows. otherwise I would have to iterate through all datasource to compare values to my wished selection and make isSelected ->true in case it matches.

                    I haven't got any more the code that was working. But I rewrited and is not working, maybe a because I changes release again?

                    Isomorphic, could you please help me out with this.. thanks!

                    Comment

                    Working...
                    X