Announcement

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

    ListGrid problem - trying to expand and use widgets

    Hi, I've run across a problem when trying to use both expanding rows and the grid cell widgets. I can expand the row but it appears that it will not collapse.

    Here is my code:

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.*;
    import com.smartgwt.client.data.*;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    import com.smartgwt.client.data.fields.DataSourceTextField;
    import com.smartgwt.client.widgets.Canvas;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class TestCase implements EntryPoint {
    
        public void onModuleLoad() {
    final ListGrid listGrid = new ListGrid(){
                @Override
                protected Canvas createRecordComponent(ListGridRecord record, Integer colNum){
                    String fieldName = getFieldName(colNum);
                    if(fieldName.equals("info")){
                        return new IButton("Info");
                    }
                    return null;
                }
    
                @Override
                protected Canvas getExpansionComponent(final ListGridRecord record) {
                    VLayout layout = new VLayout(5);
                    layout.setPadding(5);
                    Label l = new Label("Expanded row");
                    layout.addMember(l);
                    return layout;
                }
            };
            listGrid.setWidth(500);
            listGrid.setHeight(300);
    
            ListGridField lastname = new ListGridField("lastname", "Last Name");
            ListGridField firstname = new ListGridField("firstname","First Name");
            ListGridField mi = new ListGridField("mi", "MI");
            ListGridField info = new ListGridField("info", "Info");
    
            listGrid.setFields(lastname, firstname, mi, info);
            listGrid.setShowRecordComponents(true);
            listGrid.setShowRecordComponentsByCell(true);
            listGrid.setCanExpandRecords(true);
    
            TestDataSource ds = new TestDataSource();
            listGrid.setDataSource(ds);
            listGrid.fetchData();
            listGrid.draw();
        }
    
        
        public class TestDataSource extends DataSource {
            public TestDataSource(){
    
                setClientOnly(true);
                DataSourceField pk = new DataSourceIntegerField("pk");
                pk.setHidden(true);
                pk.setPrimaryKey(true);
                DataSourceField field = new DataSourceTextField("lastname");
                addField(field);
                field = new DataSourceTextField("firstname");
                addField(field);
                field = new DataSourceTextField("mi");
                addField(field);
    
                createRecord(1,"Smith", "John", "A");
                createRecord(2,"Smith", "Dave", "B");
                createRecord(3,"Smith", "Pat", "C");
                createRecord(4,"Jones", "Jim", "D");
                createRecord(5,"Jones", "Mary", "E");
                createRecord(6,"Johnson", "Paul", "F");
                createRecord(7,"Brown", "Ed", "G");
            }
    
            private void createRecord(int id, String last, String first, String mi){
                ListGridRecord record = new ListGridRecord();
                record.setAttribute("id", id);
                record.setAttribute("lastname", last);
                record.setAttribute("firstname", first);
                record.setAttribute("mi", mi);
                addData(record);
            }
        }
        
    }
    Any ideas on how I can get this to work? Thanks.

    #2
    see the FAQ for the information you should always provide when posting.

    Comment


      #3
      Oops sorry...

      GWT 2.0.3
      Smart GWT 2.1
      GWT Hosted / Development mode
      Firefox/Windows XP

      Thanks.

      Comment


        #4
        And... are there errors or warnings, etc. Please fulfill every point listed in the FAQ.

        Comment


          #5
          No errors or warnings.

          Comment


            #6
            You named your primaryKey field "pk" but provided data for the field as "id".

            Comment


              #7
              Thanks for catching that. Unfortunately that does not seem to solve my problem. My row still won't collapse after expanding.

              Comment


                #8
                Then show your updated test case.

                Comment


                  #9
                  Code:
                  import com.google.gwt.core.client.EntryPoint;
                  import com.google.gwt.user.client.ui.*;
                  import com.smartgwt.client.data.*;
                  import com.smartgwt.client.data.fields.DataSourceIntegerField;
                  import com.smartgwt.client.data.fields.DataSourceTextField;
                  import com.smartgwt.client.widgets.Canvas;
                  import com.smartgwt.client.widgets.IButton;
                  import com.smartgwt.client.widgets.grid.ListGrid;
                  import com.smartgwt.client.widgets.grid.ListGridField;
                  import com.smartgwt.client.widgets.grid.ListGridRecord;
                  import com.smartgwt.client.widgets.layout.VLayout;
                  
                  public class TestCase implements EntryPoint {
                  
                      public void onModuleLoad() {
                  final ListGrid listGrid = new ListGrid(){
                              @Override
                              protected Canvas createRecordComponent(ListGridRecord record, Integer colNum){
                                  String fieldName = getFieldName(colNum);
                                  if(fieldName.equals("info")){
                                      return new IButton("Info");
                                  }
                                  return null;
                              }
                  
                              @Override
                              protected Canvas getExpansionComponent(final ListGridRecord record) {
                                  VLayout layout = new VLayout(5);
                                  layout.setPadding(5);
                                  Label l = new Label("Expanded row");
                                  layout.addMember(l);
                                  return layout;
                              }
                          };
                          listGrid.setWidth(500);
                          listGrid.setHeight(300);
                  
                          ListGridField lastname = new ListGridField("lastname", "Last Name");
                          ListGridField firstname = new ListGridField("firstname","First Name");
                          ListGridField mi = new ListGridField("mi", "MI");
                          ListGridField info = new ListGridField("info", "Info");
                  
                          listGrid.setFields(lastname, firstname, mi, info);
                          listGrid.setShowRecordComponents(true);
                          listGrid.setShowRecordComponentsByCell(true);
                          listGrid.setCanExpandRecords(true);
                  
                          TestDataSource ds = new TestDataSource();
                          listGrid.setDataSource(ds);
                          listGrid.fetchData();
                          listGrid.draw();
                      }
                  
                      
                      public class TestDataSource extends DataSource {
                          public TestDataSource(){
                  
                              setClientOnly(true);
                              DataSourceField pk = new DataSourceIntegerField("id");
                              pk.setHidden(true);
                              pk.setPrimaryKey(true);
                              DataSourceField field = new DataSourceTextField("lastname");
                              addField(field);
                              field = new DataSourceTextField("firstname");
                              addField(field);
                              field = new DataSourceTextField("mi");
                              addField(field);
                  
                              createRecord(1,"Smith", "John", "A");
                              createRecord(2,"Smith", "Dave", "B");
                              createRecord(3,"Smith", "Pat", "C");
                              createRecord(4,"Jones", "Jim", "D");
                              createRecord(5,"Jones", "Mary", "E");
                              createRecord(6,"Johnson", "Paul", "F");
                              createRecord(7,"Brown", "Ed", "G");
                          }
                  
                          private void createRecord(int id, String last, String first, String mi){
                              ListGridRecord record = new ListGridRecord();
                              record.setAttribute("id", id);
                              record.setAttribute("lastname", last);
                              record.setAttribute("firstname", first);
                              record.setAttribute("mi", mi);
                              addData(record);
                          }
                      }
                      
                  }

                  Comment


                    #10
                    I have the same problem, any ideas ?

                    Comment


                      #11
                      Me too. It also happens with

                      Code:
                      ListGrid.setShowRollOverCanvas(true);  
                      ListGrid.setAnimateRollUnder(true);
                      when arbitrary expansions are made, no matter if
                      Code:
                      .getExpansionComponent(...)
                      is overridden or not. I have exactly the same setup as kberrisford.

                      Most likely this is a bug.

                      Comment


                        #12
                        Originally posted by kberrisford
                        Code:
                        import com.google.gwt.core.client.EntryPoint;
                        import com.google.gwt.user.client.ui.*;
                        import com.smartgwt.client.data.*;
                        import com.smartgwt.client.data.fields.DataSourceIntegerField;
                        import com.smartgwt.client.data.fields.DataSourceTextField;
                        import com.smartgwt.client.widgets.Canvas;
                        import com.smartgwt.client.widgets.IButton;
                        import com.smartgwt.client.widgets.grid.ListGrid;
                        import com.smartgwt.client.widgets.grid.ListGridField;
                        import com.smartgwt.client.widgets.grid.ListGridRecord;
                        import com.smartgwt.client.widgets.layout.VLayout;
                        
                        public class TestCase implements EntryPoint {
                        
                            public void onModuleLoad() {
                        final ListGrid listGrid = new ListGrid(){
                                    @Override
                                    protected Canvas createRecordComponent(ListGridRecord record, Integer colNum){
                                        String fieldName = getFieldName(colNum);
                                        if(fieldName.equals("info")){
                                            return new IButton("Info");
                                        }
                                        return null;
                                    }
                        
                                    @Override
                                    protected Canvas getExpansionComponent(final ListGridRecord record) {
                                        VLayout layout = new VLayout(5);
                                        layout.setPadding(5);
                                        Label l = new Label("Expanded row");
                                        layout.addMember(l);
                                        return layout;
                                    }
                                };
                                listGrid.setWidth(500);
                                listGrid.setHeight(300);
                        
                                ListGridField lastname = new ListGridField("lastname", "Last Name");
                                ListGridField firstname = new ListGridField("firstname","First Name");
                                ListGridField mi = new ListGridField("mi", "MI");
                                ListGridField info = new ListGridField("info", "Info");
                        
                                listGrid.setFields(lastname, firstname, mi, info);
                                listGrid.setShowRecordComponents(true);
                                listGrid.setShowRecordComponentsByCell(true);
                                listGrid.setCanExpandRecords(true);
                        
                                TestDataSource ds = new TestDataSource();
                                listGrid.setDataSource(ds);
                                listGrid.fetchData();
                                listGrid.draw();
                            }
                        
                            
                            public class TestDataSource extends DataSource {
                                public TestDataSource(){
                        
                                    setClientOnly(true);
                                    DataSourceField pk = new DataSourceIntegerField("id");
                                    pk.setHidden(true);
                                    pk.setPrimaryKey(true);
                                    DataSourceField field = new DataSourceTextField("lastname");
                                    addField(field);
                                    field = new DataSourceTextField("firstname");
                                    addField(field);
                                    field = new DataSourceTextField("mi");
                                    addField(field);
                        
                                    createRecord(1,"Smith", "John", "A");
                                    createRecord(2,"Smith", "Dave", "B");
                                    createRecord(3,"Smith", "Pat", "C");
                                    createRecord(4,"Jones", "Jim", "D");
                                    createRecord(5,"Jones", "Mary", "E");
                                    createRecord(6,"Johnson", "Paul", "F");
                                    createRecord(7,"Brown", "Ed", "G");
                                }
                        
                                private void createRecord(int id, String last, String first, String mi){
                                    ListGridRecord record = new ListGridRecord();
                                    record.setAttribute("id", id);
                                    record.setAttribute("lastname", last);
                                    record.setAttribute("firstname", first);
                                    record.setAttribute("mi", mi);
                                    addData(record);
                                }
                            }
                            
                        }
                        Your testcase still has errors. You haven't added the "pk" field to the datasource and your data still has "id" instead of "pk". However after correcting these I am still seeing the issue. Please file an issue in tracker.

                        Sanjiv

                        Comment


                          #13
                          This has been fixed in SVN. For reference here is the corrected testcase.

                          Code:
                          import com.google.gwt.core.client.EntryPoint;
                          import com.google.gwt.user.client.ui.Label;
                          import com.smartgwt.client.data.DataSource;
                          import com.smartgwt.client.data.DataSourceField;
                          import com.smartgwt.client.data.fields.DataSourceIntegerField;
                          import com.smartgwt.client.data.fields.DataSourceTextField;
                          import com.smartgwt.client.util.SC;
                          import com.smartgwt.client.widgets.Canvas;
                          import com.smartgwt.client.widgets.IButton;
                          import com.smartgwt.client.widgets.grid.ListGrid;
                          import com.smartgwt.client.widgets.grid.ListGridField;
                          import com.smartgwt.client.widgets.grid.ListGridRecord;
                          import com.smartgwt.client.widgets.layout.VLayout;
                          
                          public class HelloWorld implements EntryPoint {
                          
                              public void onModuleLoad() {
                          
                                  SC.showConsole();
                                  final ListGrid listGrid = new ListGrid() {
                                      @Override
                                      protected Canvas createRecordComponent(ListGridRecord record, Integer colNum) {
                                          String fieldName = getFieldName(colNum);
                                          if (fieldName.equals("info")) {
                                              return new IButton("Info");
                                          }
                                          return null;
                                      }
                          
                                      @Override
                                      protected Canvas getExpansionComponent(final ListGridRecord record) {
                                          VLayout layout = new VLayout(5);
                                          layout.setPadding(5);
                                          Label l = new Label("Expanded row");
                                          layout.addMember(l);
                                          return layout;
                                      }
                                  };
                                  listGrid.setWidth(500);
                                  listGrid.setHeight(300);
                          
                                  ListGridField lastname = new ListGridField("lastname", "Last Name");
                                  ListGridField firstname = new ListGridField("firstname", "First Name");
                                  ListGridField mi = new ListGridField("mi", "MI");
                                  ListGridField info = new ListGridField("info", "Info");
                          
                                  listGrid.setFields(lastname, firstname, mi, info);
                                  listGrid.setShowRecordComponents(true);
                                  listGrid.setShowRecordComponentsByCell(true);
                                  listGrid.setCanExpandRecords(true);
                          
                                  TestDataSource ds = new TestDataSource();
                                  listGrid.setDataSource(ds);
                                  listGrid.fetchData();
                                  listGrid.draw();
                              }
                          
                          
                              public class TestDataSource extends DataSource {
                                  public TestDataSource() {
                          
                                      setClientOnly(true);
                                      DataSourceField pk = new DataSourceIntegerField("id");
                                      pk.setHidden(true);
                                      pk.setPrimaryKey(true);
                                      addField(pk);
                          
                                      DataSourceField field = new DataSourceTextField("lastname");
                                      addField(field);
                                      field = new DataSourceTextField("firstname");
                                      addField(field);
                                      field = new DataSourceTextField("mi");
                                      addField(field);
                          
                                      createRecord(1, "Smith", "John", "A");
                                      createRecord(2, "Smith", "Dave", "B");
                                      createRecord(3, "Smith", "Pat", "C");
                                      createRecord(4, "Jones", "Jim", "D");
                                      createRecord(5, "Jones", "Mary", "E");
                                      createRecord(6, "Johnson", "Paul", "F");
                                      createRecord(7, "Brown", "Ed", "G");
                                  }
                          
                                  private void createRecord(int id, String last, String first, String mi) {
                                      ListGridRecord record = new ListGridRecord();
                                      record.setAttribute("pk", id);
                                      record.setAttribute("lastname", last);
                                      record.setAttribute("firstname", first);
                                      record.setAttribute("mi", mi);
                                      addData(record);
                                  }
                              }
                          
                          }
                          Sanjiv

                          Comment


                            #14
                            I've experienced the same problem in v 2.1. The problem doesn't appear in the nightly builds. I've actually experienced more problems in v 2.1 that are fixed recently. It would be great with a new release.

                            Comment

                            Working...
                            X