Announcement

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

    how to select/deselect a checkbox in Listgrid with group by

    SmartClient Version: SC_SNAPSHOT-2011-12-05/LGPL Development Only (built 2011-12-05)

    Chrome 34

    SmartGWT 3.0

    I have a Select All checkbox on top of ListGrid.
    Initially there is no group by applied on the ListGrid.
    So when the Select All checkbox is checked all the records are selected.
    Now I group by "name" field.
    There are two groups GROUP1 & GROUP2
    When I try to uncheck the Select All checkbox ,the records in the groups are not unchecked.(still they are in checked state)

    Following is code.

    Code:
    public class ListGridGroupBy implements EntryPoint {
    
    	CheckboxItem selectAllCheckBoxItem;
    	ListGrid grid;
    
    	@Override
    	public void onModuleLoad() {
    		grid = new ListGrid();
    		grid.setWidth(300);
    
    		ListGridField checkBoxField = new ListGridField("checkBox", " ");
    		checkBoxField.setWidth("4%");
    		checkBoxField.setAlign(Alignment.LEFT);
    		checkBoxField.setType(ListGridFieldType.BOOLEAN);
    		checkBoxField.setCanFilter(false);
    		checkBoxField.setCanEdit(true);
    		checkBoxField.setCanToggle(true);
    		checkBoxField.setDefaultValue(Boolean.FALSE);
    
    		grid.setFields(checkBoxField, new ListGridField("id", "ID"),
    				new ListGridField("name", "Name"));
    		grid.setData(createData());
    		grid.setHeight(400);
    		grid.addGroupByHandler(new GroupByHandler() {
    			@Override
    			public void onGroupBy(GroupByEvent event) {}
    		});
    
    		VLayout vlayout = new VLayout();
    		vlayout.addMember(createSelectAllForm());
    		vlayout.addMember(grid);
    		vlayout.draw();
    	}
    
    	private ListGridRecord[] createData() {
    		ListGridRecord[] records = new ListGridRecord[10];
    		for (int i = 0; i < 10; i++) {
    			records[i] = new ListGridRecord();
    			records[i].setAttribute("id", i);
    			records[i].setAttribute("name", i % 2 == 0 ? "GROUP1" : "GROUP2");
    		}
    		return records;
    	}
    
    	private DynamicForm createSelectAllForm() {
    		DynamicForm df = new DynamicForm();
    		df.setMargin(0);
    		selectAllCheckBoxItem = new CheckboxItem("selectAll", "Select All");
    		selectAllCheckBoxItem.setShowTitle(false);
    		selectAllCheckBoxItem.addChangedHandler(new ChangedHandler() {
    
    			@Override
    			public void onChanged(final ChangedEvent event) {
    				if (grid.isGrouped()) {
    
    					if (grid.getGroupTree() != null
    							&& grid.getGroupTree().getAllNodes() != null) {
    						final TreeNode[] nodes = grid.getGroupTree()
    								.getAllNodes();
    						Tree tree = grid.getGroupTree();
    						for (int i = 0; i < nodes.length; i++) {
    
    							if (nodes[i] != null && !tree.isFolder(nodes[i])) {
    								GWT.log("Logging to check if the changes are taken");
    								final TreeNode temp = nodes[i];
    								temp.setAttribute(
    										"checkBox",
    										event.getValue() instanceof Boolean ? (Boolean) event
    												.getValue() : false);
    								if ((Boolean) event.getValue()) {
    									grid.selectRecord(i);
    								} else {
    									grid.deselectRecord(i);
    								}
    								grid.refreshRow(i);
    							}
    						}
    					}
    				} else if (grid.getRecords() != null
    						&& grid.getRecords().length > 0) {
    					for (int i = 0; i < grid.getRecords().length; i++) {
    						boolean select = event.getValue() != null ? (Boolean) event
    								.getValue() : false;
    						if (select) {
    							grid.selectRecord(i);
    						} else {
    							grid.deselectRecord(i);
    						}
    						grid.setEditValue(i, 0, select);
    						grid.refreshRow(i);
    
    					}
    				}
    			}
    		});
    
    		df.setFields(selectAllCheckBoxItem);
    
    		return df;
    	}
    
    }
    Attached Files

    #2
    my example metod

    private void selectAll() {

    if (isGrouped()) {

    Tree tree = getGroupTree();
    if (tree != null) {
    selectRecords(tree.getAllNodes());
    }
    }

    selectAllRecords();
    }

    Comment


      #3
      Thanks for your input.
      Your code will select the individual records in the ListGrid.

      However ,I am having an issue at the following scenario ,

      I have row level checkboxes in the first column (defined as a ListGridField of type boolean ).

      Select All checkbox is placed on the top of the ListGrid.
      When i check the Select All checkbox, all the checkboxes on the rows in ListGrid ,are selected. This is working fine.

      But,when I group by "name" & then uncheck the "Select All" checkbox on top of the ListGrid ,individual checkboxes on rows are not getting unchecked.

      In order for the row level checkbox to be edited ( checked/unchecked ) (when Listgrid is group by ) i am using Listgrid#setAttribute("FIELDNAME",true/false) ,if the listgrid is not group by , then i am using setEditValue ( rowNum,colNumn,value)

      Not sure where I am going wrong.
      Last edited by chebus; 27 May 2014, 23:30.

      Comment


        #4
        Isomorphic,

        I guess I hit a bug ?

        I upgraded the smartgwt 3.0 to smartgwt 4.1p and tried if my code above works. I am getting following exception when i uncheck the Select All checkbox after applying group by

        Code:
        Caused by: java.lang.ClassCastException: com.smartgwt.client.widgets.grid.ListGridRecord cannot be cast to com.smartgwt.client.widgets.tree.TreeNode
            at com.smartgwt.client.util.ConvertTo.arrayOfTreeNode(ConvertTo.java:7037)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            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:172)
            at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
            at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
            at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
            at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
            at com.smartgwt.client.widgets.tree.Tree.getAllNodes(Tree.java)
            at com.listgrid.groupby.client.ListGridGroupBy$2.onChanged(ListGridGroupBy.java:76)
            at com.smartgwt.client.widgets.form.fields.events.ChangedEvent.dispatch(ChangedEvent.java:110)
            at com.smartgwt.client.widgets.form.fields.events.ChangedEvent.dispatch(ChangedEvent.java:1)
            at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
            at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
            at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
            at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
            at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
            at com.smartgwt.client.core.DataClass.fireEvent(DataClass.java:487)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            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:172)
            at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
            at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
            at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
            at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
            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:242)
            at sun.reflect.GeneratedMethodAccessor33.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:172)
            at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
            at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
            at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
            at java.lang.Thread.run(Thread.java:662)
        Can you please confirm ?

        SmartClient Version: v9.1p_2014-05-27/LGPL Development Only (built 2014-05-27)

        Comment


          #5
          Isomorphic,
          Can you please confirm if this is a bug or should I raise this as a bug ?

          Thanks!

          Comment

          Working...
          X