Announcement

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

    DateUtil.setShortDateDisplayFormatter and grid filter problem

    Hi,
    I have got a datasource with DataSourceDateField. The grid is bound to that datasource having filter visible.
    When I pick a date then local filtering works fine.
    After inserting this code:
    Code:
            DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
                public String format(Date date) {
                    if(date == null) return null;
    //                DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy-MM-dd");
                    DateTimeFormat dateFormatter = DateTimeFormat.getMediumDateFormat();
                    String format = dateFormatter.format(date);
                    return format;
                }
            });
    I have date values in the grid and its filter formatted to the local date format,
    but the same filtering by picking the same date does not work - no records found.
    svn 557

    MichalG

    #2
    These are totally unrelated subsystems - filtering works on the underlying date value, not the formatted value. If you're sure that formatting somehow affects filtering, please post a standalone test case, eg, add your custom formatter to an example showing filtering.

    Comment


      #3
      Test case

      Code:
      package org.yournamehere.client;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.google.gwt.core.client.GWT;
      import com.google.gwt.i18n.client.DateTimeFormat;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.DataSourceField;
      import com.smartgwt.client.data.WebService;
      import com.smartgwt.client.data.fields.DataSourceDateField;
      import com.smartgwt.client.data.fields.DataSourceEnumField;
      import com.smartgwt.client.data.fields.DataSourceFloatField;
      import com.smartgwt.client.data.fields.DataSourceIntegerField;
      import com.smartgwt.client.data.fields.DataSourceTextField;
      import com.smartgwt.client.types.DateDisplayFormat;
      import com.smartgwt.client.types.ListGridEditEvent;
      import com.smartgwt.client.util.DateDisplayFormatter;
      import com.smartgwt.client.util.DateUtil;
      import com.smartgwt.client.util.SC;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.layout.VLayout;
      import java.util.Date;
      import java.util.HashMap;
      
      
      public class MainEntryPoint implements EntryPoint {
      
          private static WebService wsdl = null;
      
          public void onModuleLoad() {
              if (!GWT.isScript()) {
                  SC.showConsole();
              }
      
              DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
                  public String format(Date date) {
                      if(date == null) return null;
                      DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy-MM-dd");
                      String format = dateFormatter.format(date);
                      return format;
                  }
              });
              
              final VLayout vLayout = new VLayout(10);
              final ListGrid grid = new ListGrid();
      
              grid.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
              grid.setWidth(400);
              grid.setHeight(180);
              grid.setAlternateRecordStyles(true);
              grid.setDataPageSize(50);
              grid.setAutoFetchData(false);
              grid.setCanEdit(true);
              grid.setShowFilterEditor(true);
              grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
              grid.setDataSource(EfektDS.getInstance());
      
              vLayout.addMember(grid);
              vLayout.draw();
      
              return;
          }
      
          private static class EfektDS extends DataSource {
      
              private static EfektDS instance;
      
              public static EfektDS getInstance() {
                  if (instance == null)
                      instance = new EfektDS("Efekt");
                  return instance;
              }
      
              public EfektDS(String id) {
      
                  setID(id);
                  setRecordXPath("/data/efekt");
      
                  DataSourceField idField = new DataSourceIntegerField("id", "ID", 5, false);
                  idField.setPrimaryKey(true);
                  idField.setCanEdit(false);
                  idField.setCanFilter(false);
                  idField.setHidden(true);
      
                  DataSourceField lpField = new DataSourceIntegerField("lp", "Lp", 5, false);
                  lpField.setCanFilter(false);
      
                  DataSourceField opisField = new DataSourceTextField("opis", "Opis", 256);
      
                  DataSourceField iloscField = new DataSourceFloatField("ilosc", "Ilość", 10);
      
                  DataSourceField jmrField = new DataSourceTextField("jmr", "jmr", 5);
      
                  DataSourceField wartoscField = new DataSourceFloatField("wartosc", "Wartość", 10);
      
                  DataSourceField dataOdField = new DataSourceDateField("dataOd", "Data od", 10);
      
                  DataSourceField dataDoField = new DataSourceDateField("dataDo", "Data do", 10);
      
                  DataSourceField statusField = new DataSourceEnumField("status", "Status", 30);
                  HashMap statusMap = new HashMap();
                  statusMap.put("O", "Obowiązujący");
                  statusMap.put("P", "Planowany");
                  statusMap.put("Z", "Zamknięty");
                  statusField.setValueMap(statusMap);
                  statusField.setRequired(true);
      
                  setFields(idField,lpField,opisField,iloscField,jmrField,wartoscField,dataOdField,dataDoField,statusField);
      
                  setDataURL("data/dataIntegration/xml/responses/data.xml");
                  setClientOnly(true);
              }
          }
      }

      data.xml.txt available as attachment.

      Entering date: 8'th of May 2009 in the filter field: dataOd.
      Attached png print screens first with DateUtil() commented, second with dates formated.

      Michalg
      Attached Files

      Comment


        #4
        yet another test case

        Isomorphic are you there ?

        I think this a bug of some kind, and I really need someone to look inside of it.

        Very simple test:
        Code:
        package org.yournamehere.client;
        
        import com.google.gwt.core.client.EntryPoint;
        import com.google.gwt.core.client.GWT;
        import com.google.gwt.i18n.client.DateTimeFormat;
        import com.smartgwt.client.data.DataSource;
        import com.smartgwt.client.data.DataSourceField;
        import com.smartgwt.client.data.fields.DataSourceDateField;
        import com.smartgwt.client.util.DateDisplayFormatter;
        import com.smartgwt.client.util.DateUtil;
        import com.smartgwt.client.util.SC;
        import com.smartgwt.client.widgets.grid.ListGrid;
        import com.smartgwt.client.widgets.layout.VLayout;
        import java.util.Date;
        
        
        public class MainEntryPoint implements EntryPoint {
        
            public void onModuleLoad() {
                if (!GWT.isScript()) {
                    SC.showConsole();
                }
        /*
                DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {
                    public String format(Date date) {
                        if(date == null) return null;
                        DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy-MM-dd");
                        String format = dateFormatter.format(date);
                        return format;
                    }
                });
        */
                final VLayout vLayout = new VLayout(10);
                final ListGrid grid = new ListGrid();
        
                grid.setAutoFetchData(false);
                grid.setShowFilterEditor(true);
                grid.setDataSource(EfektDS.getInstance());
        
                vLayout.addMember(grid);
                vLayout.draw();
        
                return;
            }
        
            private static class EfektDS extends DataSource {
        
                private static EfektDS instance;
        
                public static EfektDS getInstance() {
                    if (instance == null)
                        instance = new EfektDS("Efekt");
                    return instance;
                }
        
                public EfektDS(String id) {
        
                    setID(id);
                    DataSourceField dataOdField = new DataSourceDateField("dataOd", "Data od", 10);
                    setFields(dataOdField);
                    setClientOnly(true);
                }
        
            }
        
        }
        Now, pick any (not today) day in the filter date chooser. Next, click date chooser again - you should see the correct behevior that is: chooser higlight initialy your previous choosen date.

        Uncomment DateUtil.setShortDateDisplayFormatter() and make the same experiment. This time, whatever date you choose, the next time you go into date chooser, today date is highlited instead of previous choosen.

        You mentioned "underlying date value" so I assume that after using DateUtil.setShortDateDisplayFormatter() underlying data is set somehow differently.

        MichalG

        Comment


          #5
          solved

          My fault.
          Should set DateUtil.setDateInputFormatter() as well.
          MichalG

          Comment

          Working...
          X