Announcement

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

    SetFilterEditorCriteria doesn't work on MiniDateRangeItem

    Hello,

    I can't manage to set a filter editor criteria on a MiniDateRangeItem filter. Here is a sample code:

    Code:
    Date date = new Date();
    Criterion crit1 = new Criterion("date", OperatorId.LESS_OR_EQUAL, date);
    Criterion crit2 = new Criterion("date", OperatorId.GREATER_OR_EQUAL, date);
    Criterion crit3 = new Criterion(OperatorId.AND, new Criterion[] { crit1, crit2 });
    
    ListGrid listGrid = new ListGrid();
    listGrid.setShowFilterEditor(true);
    
    GWT.create(BeanFactory.FormItemMetaFactory.class);
    
    ListGridField field = new ListGridField("date", "Date");
    field.setFilterEditorType(MiniDateRangeItem.class);
    
    listGrid.setFields(field);
    
    listGrid.draw();
    
    listGrid.setFilterEditorCriteria(crit3);
    The filter editor is empty and listGrid.getFilterEditorCriteria() is null. What did I miss ?

    Thank you.

    #2
    Hi Hime,

    I assume you want to limit the range of user-selectable dates? This is not possible so far, see here.

    Best regards
    Blama

    Comment


      #3
      Thnak you for your answer.
      I just want to set a default filter when I create the grid so that only today's data are displayed

      Comment


        #4
        What happens if you do a
        Code:
        listGrid.setAutoFetchData(false);
        listGrid.fetch(crit3);
        instead?

        Besides: Does the order matter? new Criterion[] { crit2, crit1 })? This might sound unreasonable, but if you enter criteria in the MiniDateRangeItem here in the lower ListGrid and do a
        Code:
        isc_ListGrid_4.getFilterEditorCriteria().criteria[0] //adjust ListGrid_4 to your Listgrid-number
        isc_ListGrid_4.getFilterEditorCriteria().criteria[1] //adjust ListGrid_4 to your Listgrid-number
        in the eval box of the Developer Console, it starts with the GREATER_OR_EQUAL-criteria.

        But in general I agree that the behavior is a bit strange. Your listGrid.setFilterEditorCriteria(crit3) should have an effect.

        Best regards
        Blama

        Comment


          #5
          I changed the order and also tested with fetchdata but none of them worked. I would like to precise that I did not attach DataSource in my sample code, I just added fields.

          Comment


            #6
            OK, then what happens if you add the DS?

            Comment


              #7
              I made a test:

              Code:
              public class Test3 implements ClickHandler
              {
                  private ListGrid listGrid;
              
                  public void run()
                  {
                      ListGridRecord record1 = new ListGridRecord();
                      record1.setAttribute("date", new Date());
                      ListGridRecord record2 = new ListGridRecord();
                      record2.setAttribute("date", new Date());
              
                      //        DataSourceField dsField = new DataSourceField("date", FieldType.DATE, "Date");
              
                      DataSource dataSource = new DataSource();
                      dataSource.setClientOnly(true);
                      dataSource.setTestData(record1, record2);
                      //        dataSource.setFields(dsField);
              
                      GWT.create(BeanFactory.FormItemMetaFactory.class);
              
                      ListGridField field = new ListGridField("date", "Date");
                      field.setFilterEditorType(MiniDateRangeItem.class);
              
                      listGrid = new ListGrid();
                      listGrid.setShowFilterEditor(true);
                      listGrid.setWidth(500);
                      listGrid.setHeight(500);
                      listGrid.setDataSource(dataSource);
                      listGrid.setFields(field);
                      listGrid.setAutoFetchData(true);
              
                      Button button = new Button("Filter");
                      button.addClickHandler(this);
              
                      VLayout layout = new VLayout();
                      layout.setMembers(button, listGrid);
                      layout.draw();
                  }
              
                  @Override
                  public void onClick(ClickEvent event)
                  {
                      Date date = new Date();
                      Criterion crit1 = new Criterion("date", OperatorId.GREATER_OR_EQUAL, date);
                      Criterion crit2 = new Criterion("date", OperatorId.LESS_OR_EQUAL, date);
                      Criterion crit3 = new Criterion(OperatorId.AND, new Criterion[] { crit1, crit2 });
              
                      listGrid.setFilterEditorCriteria(crit3);
                  }
              }
              This does not work. When I click on "Filter" button, it does nothing.
              I made it work once by uncommenting the commented lines, but it does not work anymore and I don't know why.
              Last edited by Hime; 7 Jan 2016, 00:06.

              Comment


                #8
                Does it work with fetchData(crit3)?

                I'm pretty sure you'll also need your DataSourceField definition. Besides of that, this does not look like builtInDS-Sample (different implements). I don't know if this matters, I just noticed it.

                Best regards
                Blama

                Comment


                  #9
                  I tried with fetchData(crit3), still nothing. I also changed crit3 to :
                  Code:
                  AdvancedCriteria crit3 = new AdvancedCriteria();
                  crit3.addCriteria(crit1);
                  crit3.addCriteria(crit2);
                  Did not change anything.
                  I didn't understand what you said about builtInDS-Sample ?

                  Comment


                    #10
                    Hi Hime,

                    strange, then perhaps it is a bug.

                    Regarding builtInDS: Normal testcases look like the BuiltInDS sample (see your SmartGWT samples/built-in-ds directory in Pro/Power/EE or helloworld-2.0 directory in LGPL):

                    Code:
                    public class BuiltInDS implements EntryPoint {
                        public void onModuleLoad() {
                        
                        ...your code...
                        layout.draw();
                        }
                    }
                    Does this setup change anything?

                    Comment


                      #11
                      Ah, I see ! I changed the setup, deleted gwt-unitcache and every gwt file or folder in %APPDATA%/local/temp, but still no luck.
                      I didn't say it, but I use GWT 2.6.0 and smartgwt-lgpl-5.0-p20151019.jar and I'm in DevMode on IE 11.
                      I just tried with listGrid.filterData(crit3) :
                      Code:
                      Button button = new Button("Filter");
                      button.addClickHandler(new ClickHandler()
                      {
                          @Override
                          public void onClick(ClickEvent event)
                          {
                              Date date = new Date();
                              Criterion crit1 = new Criterion("date", OperatorId.GREATER_OR_EQUAL, date);
                              Criterion crit2 = new Criterion("date", OperatorId.LESS_OR_EQUAL, date);
                              Criterion crit3 = new Criterion(OperatorId.AND, new Criterion[] { crit1, crit2 });
                      
                              listGrid.filterData(crit3);
                          }
                      });
                      After the listGrid.filterData(crit3), if I display listGrid.getFilterEditorCriteria().asAdvancedCriteria().getValues(), I get :
                      Code:
                      {_constructor=AdvancedCriteria, operator=and, criteria=[{fieldName=operator, operator=iContains, value=and}]}
                      And still nothing in my filter editor.

                      Comment


                        #12
                        OK, then perhaps post your whole file and let Isomorphic have a look.

                        Best regards
                        Blama

                        Comment


                          #13
                          You can also try with a more current nightly. Perhaps this helps.

                          Comment


                            #14
                            I just tried with the latest smartgwt 5.1p build (2016-01-06) and it finally works ! Thank you for your help, here is my final code:
                            Code:
                            public class Test implements EntryPoint
                            {
                            
                                @Override
                                public void onModuleLoad()
                                {
                                    ListGridRecord record1 = new ListGridRecord();
                                    record1.setAttribute("date", new Date());
                                    ListGridRecord record2 = new ListGridRecord();
                                    record2.setAttribute("date", new Date());
                            
                                    DataSourceField dsField = new DataSourceField("date", FieldType.DATE, "Date");
                            
                                    DataSource dataSource = new DataSource();
                                    dataSource.setClientOnly(true);
                                    dataSource.setTestData(record1, record2);
                                    dataSource.setFields(dsField);
                            
                                    GWT.create(BeanFactory.FormItemMetaFactory.class);
                            
                                    ListGridField field = new ListGridField("date", "Date");
                                    field.setFilterEditorType(MiniDateRangeItem.class);
                            
                                    final ListGrid listGrid = new ListGrid();
                                    listGrid.setShowFilterEditor(true);
                                    listGrid.setWidth(500);
                                    listGrid.setHeight(500);
                                    listGrid.setDataSource(dataSource);
                                    listGrid.setFields(field);
                                    listGrid.setAutoFetchData(true);
                            
                                    Button button = new Button("Filter");
                                    button.addClickHandler(new ClickHandler()
                                    {
                                        @Override
                                        public void onClick(ClickEvent event)
                                        {
                                            Date date = new Date();
                                            Criterion crit1 = new Criterion("date", OperatorId.GREATER_OR_EQUAL, date);
                                            Criterion crit2 = new Criterion("date", OperatorId.LESS_OR_EQUAL, date);
                                            Criterion crit3 = new Criterion(OperatorId.AND, new Criterion[] { crit1, crit2 });
                            
                                            listGrid.filterData(crit3);
                                        }
                                    });
                            
                                    VLayout layout = new VLayout();
                                    layout.setMembers(button, listGrid);
                                    layout.draw();
                                }
                            }

                            Comment

                            Working...
                            X