Announcement

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

    getDefaultFormattedValue not being called?!

    The method getDefaultFormattedValue() is not being called for my listgrid.

    Here is sample code from a modified showcase example:

    Code:
    package zedes2.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.widgets.grid.ListGrid;
    
    public class Alternate implements EntryPoint {
        
        public void onModuleLoad() {  
            
            final ListGrid countryGrid = new ListGrid() {
                @Override
                public String getDefaultFormattedValue( Record record, int rowNum, int colNum )
                {
                    System.out.println("Entering getDefaultFormattedValue");
                    return super.getDefaultFormattedValue( record, rowNum, colNum );
                }
            };          
            countryGrid.setWidth(500);  
            countryGrid.setHeight(224);  
            countryGrid.setShowAllRecords(true);  
            countryGrid.setDataSource(CountryDS.getInstance()); 
            countryGrid.setAutoFetchData(true);  
            countryGrid.setCanEdit(true);
            
            countryGrid.draw();   
        }  
        
        private static class CountryDS extends DataSource {  
            // The DataSource would normally be defined external to any classes that use it.  
      
            private static CountryDS instance = null;  
              
            public static CountryDS getInstance() {  
                if (instance == null) {  
                  instance = new CountryDS("countryDS_DS");  
                }  
                return instance;  
            }  
      
            public CountryDS(String id) {  
                setID(id);  
                setRecordXPath("/List/country");  
                DataSourceField countryNameField = new DataSourceField("countryName", FieldType.TEXT, "Country");  
                DataSourceField countryCodeField = new DataSourceField("countryCode", FieldType.TEXT, "Code");  
                DataSourceField independenceField = new DataSourceField("independence", FieldType.DATE, "Independence");  
                DataSourceField populationField = new DataSourceField("population", FieldType.INTEGER, "Population");  
                DataSourceField gdpField = new DataSourceField("gdp", FieldType.FLOAT, "GDP ($B)");  
      
                setFields(countryNameField, countryCodeField, independenceField, populationField, gdpField);  
                //EDIT BEGIN
                setDataURL("ds/country.data.xml");
                //EDIT END
            }  
      
        }  
      
    }
    The System.out.println("Entering getDefaultFormattedValue"); is never being called.

    Using SmartGWT EE 3.0p

    #2
    This is not an override point, it's a convenience method for you. Use a CellFormatter to format cell values.

    Comment


      #3
      Ah ok, thanks.

      What I need to do is to set a cell value to 'x' for some cases, or to '-' for other cases.

      Something like "getBaseStyle( ListGridRecord record, int rowNum, int colNum )", but instead of returning the base style, returning the value.

      What can I use for this case?
      I know I could use a field in my datasource, but I'd prefer some override point like getBaseStyle( ListGridRecord record, int rowNum, int colNum ).
      Is there anything like that?
      Or how could I use the getDefaultFormattedValue() for this use case?

      Comment


        #4
        Once again, add a CellFormatter.

        Comment

        Working...
        X