Announcement

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

    Expanding the grid and using cell widgets

    I am using a grid which has expanding rows and grid cell widgets.

    My problem is when i am expanding the row the button widget is moving to the expanded row and when i close the expanded row the button is coming back.

    Can someone please let me know how to put the button in fixed position on row instead of moving to expanded row.

    I am using smartgwt EE.

    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);
            }
        }
    
    }
    Please see the attached images for clarity.

    Thanks
    Attached Files
    Last edited by anish03; 17 Aug 2010, 11:48.

    #2
    You can use snapTo positioning, eg, setSnapTo(TL) and setLeft(3), setTop(3) for some padding.

    Comment


      #3
      Thankyou Isomorphic. I tried the above methods but my problem didn't get resolved.

      Also I have to display two buttons instead of one shown in above example. I use HLayout and added the buttons as members. Now i am getting the warn message
      : startEditing() passed bad cell coordinates:,, can't edit.

      Can someone explain how to set the button in correct position and to get rid of warning msg.

      Thanks

      Comment


        #4
        No one can tell what's gone wrong until you post your code.

        Comment


          #5
          Code:
          protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {
           
                          String fieldName = this.getFieldName(colNum);
          
                          HLayout recordCanvas = new HLayout(3);
                          recordCanvas.setHeight(22);
                          recordCanvas.setAlign(Alignment.CENTER);
                          recordCanvas.setSnapTo("TL");
                       //recordCanvas.setTop(3);      
                          
                          if (fieldName.equals("buttonField")) {
                              return getDisplayButton(record, recordCanvas);
                          }
                         
                          return null;
          
                      }
          The method getDisplayButton displays buttons corresponding to value in field.

          Code:
          private HLayout getDisplayButton(ListGridRecord record,HLayout recordCanvas) {
                    
                     if (flag) {
                           recordCanvas.addMember(addAButton());
                       } else {
                           recordCanvas.addMember(addBButton());
                           recordCanvas.addMember(addCButton());
                       }
                         return recordCanvas;
               }
          and i am getting the above mentioned warning and the buttons alignment didn't get fixed.

          Comment


            #6
            Regarding the warning, you haven't posted code showing how/when you are calling the startEditingNew() API, which is what the warning is about.

            You've also omitted all version information. Try upgrading to the latest version, or even the latest nightly build (there was one recent fix post 2.3, which shouldn't affect you, but then you're reporting a problem no one's seeing..).

            Comment


              #7
              Regarding the warning, please ignore as i figured out. But still the problem with alignment is not fixed, I am using smartgwt 2.3.

              Comment


                #8
                hi, could you post what measures fixed your issue? I'm facing the same "bad cell coordinates" problem :(

                regards
                T.

                Comment

                Working...
                X