Announcement

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

    TreeGrid loosing titleField after adding TreeGridField

    Hi,
    I someone could look into this (I am struggling with it for a while).
    This is a very simple TreeGrid example with titleField set in the DataSource:
    Code:
    package org.yournamehere.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.widgets.tree.TreeGrid;
    import com.smartgwt.client.widgets.tree.TreeGridField;
    
    public class MainEntryPoint implements EntryPoint {
    
    
        public void onModuleLoad() {
            TreeGrid testTreeGrid = new TreeGrid();
            testTreeGrid.setWidth(300);
            testTreeGrid.setHeight(100);
            testTreeGrid.setAutoFetchData(true);
            testTreeGrid.setDataSource(TestDS.getInstance());
            testTreeGrid.setUseAllDataSourceFields(true);
    
            TreeGridField versionField = new TreeGridField("version");
    //        testTreeGrid.setFields(versionField);
    
            testTreeGrid.draw();
        }
    
    }
    Code:
    package org.yournamehere.client;
    
    import com.smartgwt.client.data.RestDataSource;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    
    public class TestDS extends RestDataSource {
    
        private static TestDS instance = null;
    
        public static TestDS getInstance() {
            if (instance == null) {
                instance = new TestDS("Umowa");
            }
            return instance;
        }
    
        public TestDS(String id) {
            setID(id);
            setDataURL("response.xml");
            setTitleField("version");
            DataSourceIntegerField idField = new DataSourceIntegerField("id", "ID");
            idField.setPrimaryKey(true);
            DataSourceIntegerField versionField = new DataSourceIntegerField("version", "Version");
            DataSourceIntegerField aneksField = new DataSourceIntegerField("aneks", "Aneks");
            aneksField.setForeignKey("Umowa.id");
            aneksField.setHidden(true);
            setFields(idField, versionField, aneksField);
        }
    }
    Code:
    <response>
        <status>STATUS_SUCCESS</status>
        <startRow>0</startRow>
        <endRow>2</endRow>
        <totalRows>2</totalRows>
    
        <data>
            <Umowa>
                <id>393216</id>
                <version>59</version>
                <nrUmowy>123/8</nrUmowy>
            </Umowa>
            <Umowa>
                <id>458752</id>
                <version>6</version>
                <nrUmowy>123/9</nrUmowy>
                <aneks>393216</aneks>
            </Umowa>
        </data>
    </response>
    If testTreeGrid.setFields(versionField) is commented out then I got such view:

    which uses titleField correctly as pointed too the versionField.

    But if testTreeGrid.setFields(versionField) is processed then I got such output:

    This time there is no Name at all and id's are displayed instead of version column values.
    The only difference is that I am defining TreeGridField just to set some properties for it.
    Thanks for any help / explanation.
    MichalG
    ps SmartGWT svn 1307, GWT 2.0.4
    Last edited by michalg; 5 Aug 2010, 07:28.

    #2
    Is your goal to only show the version information, a single column? If so then define your datasource that way. Note how you had a field like aneksField which is hidden, you can still do TreeNode.getAttribute("aneks") even if that field doesn't show up in the view.

    Comment


      #3
      My goal is to have TreeGrid with fields merged from DataSource and some of them defined as TreeGridField.
      Additionally I want to set one of fields as a titleField.
      The example I presented was intentionally striped as production one has a lot of fields, just to make it as simple as possible.

      Anyway, it would be more convenient to experiment on the showcase example: Tree->Appearance->Multiple Columns.

      First, if I change EmployeeXmlDS.java from:
      setTitleField("Name");
      to:
      setTitleField("Job");
      nothing changed in the output - still Name as title field.

      Second, comment out in MainEntryPoint.java:
      // treeGrid.setFields(nameField, jobField, salaryField);
      This time Job field is displayed as title field as requested in DataSource definition.

      Third, change the order of setFields in MainEntryPoint from:
      treeGrid.setFields(nameField, jobField, salaryField);
      to:
      treeGrid.setFields(jobField, nameField, salaryField);
      Now job field is displayed as title, but I would think that this is just because job field is first in the setFields list.
      My other tries (other than changing fields order) such:
      treeGrid.setTitleField("Job") etc seems not working at all.

      MichalG

      Comment


        #4
        Dynamically adding/removing fields is not supported, so the use case your talking about won't work since Datasourcefields basically is one call to setFields() and then you are doing an additional call to setFields(), its is a one time thing, otherwise your simply overwriting NOT merging from the previous call. Again I don't see why you can't define them all as DataSourceFields?

        Comment


          #5
          I am only following showcase example:
          Code:
          public class MultipleColumnsSample implements EntryPoint {
          
              public void onModuleLoad() {
          
                  EmployeeXmlDS employeesDS = EmployeeXmlDS.getInstance();
          
                  TreeGrid treeGrid = new TreeGrid();
                  treeGrid.setCanEdit(true);
                  treeGrid.setLoadDataOnDemand(false);
                  treeGrid.setWidth(500);
                  treeGrid.setHeight(400);
                  treeGrid.setDataSource(employeesDS);
                  treeGrid.setNodeIcon("icons/16/person.png");
                  treeGrid.setFolderIcon("icons/16/person.png");
                  treeGrid.setShowOpenIcons(false);
                  treeGrid.setShowDropIcons(false);
                  treeGrid.setClosedIconSuffix("");
                  treeGrid.setAutoFetchData(true);
          
                  TreeGridField nameField = new TreeGridField("Name");
                  TreeGridField jobField = new TreeGridField("Job");
                  TreeGridField salaryField = new TreeGridField("Salary");
                  salaryField.setCellFormatter(new CellFormatter() {
                      public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                          if(value != null) {
                              NumberFormat nf = NumberFormat.getFormat("#,##0");
                              try {
                                  return "$" + nf.format(((Number)value).longValue());
                              } catch (Exception e) {
                                  return value.toString();
                              }
                          } else {
                              return null;
                          }
                      }
                  });
          
                  treeGrid.setFields(nameField, jobField, salaryField);
                  treeGrid.draw();
              }
          
          }
          Now, let's say I want to have all DataSource fields in grid:
          Code:
                  ...
                  treeGrid.setUseAllDataSourceFields(true);
                  treeGrid.setFields(nameField, jobField, salaryField);
                  ...
          And I want Mail field to be used as titleField - How can I achive that?
          I would say that I should use DataSource.setTitleField("Mail"), but it doesn't work. The only way I found so far is changing fields order in DS (place mailField as first field) which does not seem to be elegant and right way to me ?
          MichalG

          Comment

          Working...
          X