Announcement

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

    How to properly use setFilterEditorProperties(new MiniDateRangeItem) for DateTime

    Hi Isomorphic.

    I have a custom class that extends ListGrid and in this class I iterate through all the ListGridFields setting some special configurations and customizations. One of those customizations is to add a MiniDateRangeItem filter editor to all my Date and DateTime fields, in order to be able to use the advanced filtering options this control provides.

    For this, I tried using the following code:

    Code:
    private void addMiniDateRangeItems(ListGridField field) {
        ListGridFieldType fieldType = field.getType();
        if((fieldType == ListGridFieldType.DATE) || (fieldType == ListGridFieldType.DATETIME)){
            MiniDateRangeItem dateRange = new MiniDateRangeItem();
            field.setFilterEditorProperties(dateRange);
        }
    }
    But it didn't work for my DateTime fields. On the other hand, using a Custom Data Binding (see code below), I got it to work for both fields types. So my question is if this is the correct approach to handle this case?

    Code:
    private void addMiniDateRangeItems(ListGridField field) {
        ListGridFieldType fieldType = field.getType();
        if((fieldType == ListGridFieldType.DATE) || (fieldType == ListGridFieldType.DATETIME)){
            ListGridField dateField = new ListGridField(field.getName());
    ​        MiniDateRangeItem dateRange = new MiniDateRangeItem();
            dateField.setFilterEditorProperties(dateRange);
            grid.setFields(dateField);
        }
    }
    Thanks

    ps. if instead of being lack of knowledge on my part, this turns out to be a bug, I can provide a test case for you to reproduce it.

    SmartGWT 6.0p 2016-05-31

    #2
    Use setFilterEditorType() to establish the basic type of control used.

    Comment


      #3
      Hi Isomorphic. Thanks for your response. Unfortunately, the result is the same than in my first example above.

      For DateTime items I get this control displayed:
      Click image for larger version

Name:	DateTimeFilterEditor.png
Views:	293
Size:	38.2 KB
ID:	238556


      But for Date items I get the appropriate control:
      Click image for larger version

Name:	DateFilterEditor.png
Views:	252
Size:	18.3 KB
ID:	238557


      Here is a full test case I used to try your suggestion.

      TestCases.java
      Code:
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.types.ListGridFieldType;
      import com.smartgwt.client.widgets.form.fields.MiniDateRangeItem;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.grid.ListGridField;
      import com.smartgwt.client.widgets.layout.HLayout;
      import com.google.gwt.core.client.EntryPoint;
        
      public class TestCases implements EntryPoint {  
          
          public void onModuleLoad() {        
              ListGrid grid = new ListGrid(DataSource.get("log"));
              grid.setUseAllDataSourceFields(true);
              grid.setAutoFetchData(true);
              grid.setShowFilterEditor(true);
          
              HLayout layout = new HLayout();
              layout.setWidth100();
              layout.setHeight100();
              layout.addMember(grid);
              layout.show();
      
              addMiniDateRangeItems(grid);
          }
          
          private void addMiniDateRangeItems(ListGrid grid) {
              // set MiniDateRangeItem as filter editor type for Date and DateTime fields
              ListGridField[] fields = grid.getAllFields();
              for (ListGridField field: fields) {
                  ListGridFieldType fieldType = field.getType();
                  if ((fieldType == ListGridFieldType.DATE) || (fieldType == ListGridFieldType.DATETIME)) {
                      MiniDateRangeItem dateRange = new MiniDateRangeItem();
                      [B]field.setFilterEditorType(dateRange);[/B]
                  }
              }
              grid.markForRedraw();
          }
      }
      log.ds.xml
      Code:
      <DataSource
          ID="log"
          serverType="sql"
          tableName="log"
          xmlns:fmt="WEB-INF/"
          autoDeriveSchema="true"
      >
          <fmt:bundle basename="com.myApp.testcases.shared.i18n.MyResources" encoding="utf-8"/>
          <fields>
          
              <field name="id" type="sequence" primaryKey="true" hidden="true">
              </field>
              
              <field name="time_stamp" type="datetime">
                  <title><fmt:message key="log_timeStamp"/></title>
              </field>        
      
              <field name="level">
                  <title><fmt:message key="log_level"/></title>
                  <valueMap>
                      <value id="E"><fmt:message key="log_levelError"/></value>
                      <value id="W"><fmt:message key="log_levelWarning"/></value>
                      <value id="I"><fmt:message key="log_levelInfo"/></value>
                  </valueMap>
              </field>
              
              <field name="category">
                  <title><fmt:message key="log_category"/></title>
                  <valueMap>
                      <value id="FL"><fmt:message key="log_categoryFileLoad"/></value>
                      <value id="PER"><fmt:message key="log_categoryPerformance"/></value>
                  </valueMap>
              </field>
              
              <field name="message">
                  <title><fmt:message key="log_message"/></title>
              </field>
              
              <field name="username">
                  <title><fmt:message key="log_userName"/></title>
              </field>
              
          </fields>
      </DataSource>
      Am I missing something here?

      ps. replacing the addMiniDateRangeItems with the one provided in my second example of post # 1 yields the expected behavior.

      Thanks
      Last edited by carlossierra; 9 Jun 2016, 14:24. Reason: Code formatting

      Comment


        #4
        Looks like you figured it out - you can't grab and modify fields in the way your code is doing, you need to either use setFieldProperties() for incremental changes, or setFields() to replace all fields.

        Comment


          #5
          Thanks Isomorphic. One more question: can you provide a link to a demo or some sample code that shows how do the incremental changes you mention using setFieldProperties()?
          I haven't been able to get that to work in any possible way...

          Comment


            #6
            If you were trying to use it to set filterEditorType, it would not work for that purpose in SGWT.

            Comment


              #7
              Ok. It's clear. Thanks Isomorphic.

              Comment


                #8
                Hi Isomorphic. One related question to the same test case shown in post # 3: when the date field is marked at the database level as nullable/optional, the code provided in that post doesn't work, as the filter editor that gets displayed is the default date/datetime editor (the first image shown in post # 3).

                Is this expected behavior?

                Thanks

                Comment


                  #9
                  Could you clarify what SQL schema you're using to declare this field, and also show the DataSource definition that results? You can capture the JSON for the DataSource definition by using browser tools to look at the DataSourceLoader servlet response.

                  Comment


                    #10
                    Thanks Isomorphic. By looking at the JSON definition I was able to pinpoint a bug in my code.
                    Thanks for your help!!

                    Comment

                    Working...
                    X