Announcement

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

    Group by multiple fields possible?

    According to this thread
    http://forums.smartclient.com/showthread.php?t=2681&highlight=subgroup
    it seems grouping by multiple fields is supported in smartclient at least programmatically for quite a while.
    Is this also supported in smartGWT?
    The ListGrid's signature is just
    Code:
    ListGrid.setGroupByField(String field)
    so it seems it just supports one field to group by.

    Thanks
    fatzopilot

    #2
    Added ListGrid.setGroupByField(String... field) to SVN.

    Sanjiv

    Comment


      #3
      Originally posted by sjivan
      Added ListGrid.setGroupByField(String... field) to SVN.

      Sanjiv
      I see ListGrid supports multiple grouping from java. What I am missing is how multiple grouping (sub-grouping) can be done from the user iface using the javascript drop-down. Everytime the user selects a grouping from the drop-down the current grouping (single or multiple) is lost.

      any hints?

      Comment


        #4
        There's no user interface for it yet. You could build your own by adding new menu items (eg "Grouping...") or it would be a valid Feature Sponsorship to have a default UI added to the framework.

        Comment


          #5
          Multiple grouping is the only thing stopping me from using smartgwt for a current project. I know Java and Javascript but am new to the GWT framework and how I would add this feature to the existing library. Since the project has a short delivery time what is the effort for someone like me to implement?

          Since this is already supported in the java code I imagine it is to add it to the javascript library?

          Comment


            #6
            You don't need any JavaScript - best not to think in terms of JavaScript at all when working with SmartGWT. Normal subclassing and extensions are all done via just Java. In this case, if you wanted to build this yourself, you'd override ListGrid.getHeaderContextMenuItems() and add your own menu items to do multi-level grouping.

            Your MenuItems could have submenus (Group By.. Then By..) or you might launch a dialog based on the Window class. Either way, the result should be a call to ListGrid.groupBy().

            Comment


              #7
              Thanks, that is very helpful. I may not get to this added feature for several weeks but will let you know how I make out.

              Comment


                #8
                hardtail29,

                Did you end up implementing this? If so, would you like to share some code or at least your ideas on what the UI looks like?

                Thanks.

                Comment


                  #9
                  No, I haven't gotten to it yet. There is another problem and that is when you group with multiple columns summary fields do not properly calculate for the top group. See thread http://forums.smartclient.com/showthread.php?t=17142

                  Comment


                    #10
                    I implemented menu-driven multiple group by in a ListGrid with the following override of a ListGrid method. I chose to override the default Grouping behavior from "reset the single group" to "add a level of grouping to the existing set of grouping fields."
                    This, combined with the preexisting "ungroup" option, seems to allow the user arbitrary grouping ability, from the normal popup menu.

                    Code:
                    @Override  
                    protected MenuItem[] getHeaderContextMenuItems(final Integer fieldNum) 
                    {  
                    	MenuItem newGroupBy = new MenuItem("Group by " + ListGridAdapter.this.getField(fieldNum).getTitle());  
                    	newGroupBy.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() {  
                    		public void onClick(MenuItemClickEvent event){
                    			String[] existingGroupByFields = getGroupByFields();
                    			String[] newGroupByFields = null;
                    			if ( existingGroupByFields == null ) {
                    				newGroupByFields = new String[]{ListGridAdapter.this.getFieldName(fieldNum)};
                    			}
                    			else {
                    				newGroupByFields = new String[existingGroupByFields.length + 1];
                    				for (int i = 0; i < existingGroupByFields.length; i++) {  
                    					newGroupByFields[i] = existingGroupByFields[i];  
                    				}
                    				newGroupByFields[existingGroupByFields.length] = ListGridAdapter.this.getFieldName(fieldNum);
                    			}
                    			ListGridAdapter.this.ungroup();
                    			setGroupStartOpen("all");
                    			ListGridAdapter.this.groupBy(newGroupByFields);
                    		}
                    	});
                    	
                    	final MenuItem[] originalMenuItems = super.getHeaderContextMenuItems(fieldNum);  
                    	MenuItem[] toReturn = new MenuItem[originalMenuItems.length];  
                    	for (int i = 0; i < originalMenuItems.length; i++) {
                    		String title = originalMenuItems[i].getTitle();
                    		toReturn[i] = originalMenuItems[i];  
                    		if ( title != null && title.startsWith("Group by") )
                    		{
                    			toReturn[i] = newGroupBy;
                    		}
                    	}
                    	return toReturn;  
                    } ;

                    Comment


                      #11
                      Hi jsres,

                      thank you very much for sharing.
                      I tested your code and it seems to work very well.

                      Isomorphic, any chance of getting this into the main trunk?

                      EDIT: Selecting the grouping granularity like "by day" or "by week" (works only for fields with supported data type) does not work any more using this solution

                      Regards,
                      fatzopilot
                      Last edited by fatzopilot; 24 Aug 2011, 05:07.

                      Comment


                        #12
                        I've implemented this as well, but modified slightly to remove the field from the groupBy list if it is already there or add it if not.

                        Is there some way to leverage the full set of standard group by options (i.e. grouping granularity) and still modify the behavior so it adds the new field to the group by list instead of replacing it with the single field?

                        Another problem I've run into with this. We need to support I18N so I've changed the logic that replaces the standard Group by ... menu item. I need to check for a match with getGroupByText() instead of looking for a menu title that startsWith("Group by"). But when I make a reference to getGroupByText() I get this error. Any ideas?
                        Code:
                        16:40:32.054 [ERROR] [ipgui] Uncaught exception escaped
                        
                        com.google.gwt.core.client.JavaScriptException: (TypeError): _1 is undefined
                            at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:237)
                            at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:132)
                            at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
                            at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
                            at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
                            at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
                            at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:214)
                            at sun.reflect.GeneratedMethodAccessor151.invoke(Unknown Source)
                            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                            at java.lang.reflect.Method.invoke(Method.java:597)
                            at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
                            at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
                            at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:167)
                            at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:281)
                            at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:531)
                            at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:352)
                            at java.lang.Thread.run(Thread.java:680)

                        Comment


                          #13
                          A call to getGroupByText() should work fine (very crude test demonstrating this):
                          Code:
                                  ListGrid foo = new ListGrid();
                                  SC.say(foo.getGroupByText());
                          If you can show us code that fails, we'll be happy to take a look. You could also try hitting the app in compiled mode in Internet Explorer and look for the javascript error stack trace logged in developer console - that might clarify where that missing "_1" is coming from.

                          Comment


                            #14
                            I've switched to replacing the Ungroup menu item which actually fits my purposes better. I was getting that missing _1 error consistently though when trying to replace the "Group by" item..

                            The difference might be that my code making the call to getGroupByText() was executing inside an override to getHeaderContextMenuItems() after calling super.getHeaderContextMenuItems(fieldNum).

                            Not sure if that would make a difference or not.

                            Comment


                              #15
                              I've issues implementing the solution of jsres cause i cannot find the class ListGridAdapter used in this solution. Any Hint of how to get around this?

                              Comment

                              Working...
                              X