Announcement

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

    Filter on ListGridField option datasource display field

    SmartClient Version: v11.0p_2016-05-28/Pro Deployment (built 2016-05-28)

    Hi, I have a ListGrid with filterLocalData:true and a ListGridField with an optionDatasource.

    By default the filterEditor for this field is a SelectItem with all the options from the option datasource, but since this can have quite a few options, I would like instead to have a TextItem which filters on the value of the displayField as if it had been a normal text field.

    I have changed the filterEditor to a TextItem via setFilterEditorProperties(new TextItem()) but I can't figure our how to make it filter against the displayField, if that is possible.

    #2
    You can use formItem.criteriaField to target a particular field.

    Note you want to use setFilterEditorType() if what you're doing is changing type, and not properties.

    Comment


      #3
      Hi Isomorphic,

      I (not the OP) am as well doing setFilterEditorProperties(new SomeFormItem()) when changing the FormItem-Subclass to use.
      Is this not correct? Could you please elaborate, as it has been working in all cases for me, so far.

      Thank you & Best regards
      Blama

      Comment


        #4
        Nothing to elaborate on really - the correct API to change type is setFilterEditorType().

        In limited cases, setFilterEditorProperties() may work, but it's not guaranteed to do so.

        Comment


          #5
          Okay so I need to have the display field value in a hidden field and then target that with formItem.criteriaField?

          I got it working like this but I am not sure if there is an easier way.

          Code:
          GWT.create(BeanFactory.FormItemMetaFactory.class);
          
          ListGridField taskField = new ListGridField("taskId", "Task");
          taskField.setWidth(150);
          taskField.setOptionDataSource(taskDS);
          taskField.setOptionCriteria(new Criteria("includeClosed", "true"));
          taskField.setValueField("taskId");
          taskField.setDisplayField("title");
          taskField.setEditorProperties(taskEditor);
          taskField.setFilterEditorType(TextItem.class);
          
          TextItem filterEditorProperties = new TextItem();
          filterEditorProperties.setOperator(OperatorId.ICONTAINS);
          filterEditorProperties.setCriteriaField("taskName");
          taskField.setFilterEditorProperties(filterEditorProperties);
          The datasource has a hidden field called taskName which contains the same string as the displayField value of taskId.

          Code:
          <DataSource  
              ID="dashboard_weekly_workItems"
              serverConstructor="it.forecast.server.servlets.dashboard.DashboardWeeklyWorkItemsServlet">
              <fields>  
                  <field name="id"            type="sequence"    hidden="true"    primaryKey="true"    />
                  <field name="project"        type="integer"    required="true"                        />
                  <field name="taskId"        type="integer"    required="true"                        />
                  <field name="taskName"        type="text"        hidden="true"                        />
                  <field name="costType"        type="integer"    hidden="true"                        />
                  <field name="absence"        type="boolean"  hidden="true"                        />
              </fields>
          </DataSource>
          Is that the right approach?

          Comment


            #6
            Hi Niels_EMP,

            I'm pretty sure that this is working without any further setup (no filterEditorProperties) in Java if you define it like this:
            Code:
            <field name="taskId" type="integer" required="true" [B]displayField="taskName"[/B] />
            This wont display the taskId as data in the ListGrid as well, but most likely this is not intended anyway.

            Did you try this already?

            Best regards
            Blama

            Comment


              #7
              Hi Isomorphic,

              Originally posted by Isomorphic View Post
              Nothing to elaborate on really - the correct API to change type is setFilterEditorType().

              In limited cases, setFilterEditorProperties() may work, but it's not guaranteed to do so.
              thanks, the docs are pretty clear on this. I think I'm not affected by these limitations for very advanced use cases or worked around them so far, but it is good to know that there might be a problem in the future and that then there is something one can do.
              Besides the issues covered in the docs it is valid and OK (even though not best practice) to use setFilterEditorProperties() instead of setFilterEditorType(), isn't it?

              Best regards
              Blama

              Comment


                #8
                It's valid to use setFilterEditorProperties to provide properties. To change the type, use setFilterEditorType().

                Comment


                  #9
                  Just a follow up question.
                  Does filterLocalData:true automatically set saveLocally:true ?
                  When I turn on local filtering the grid no longer sends update requests to the server.

                  Comment


                    #10
                    The two properties can be independently set, but saveLocally defaults to true if filterLocalData is set. We'll make sure this is clearer in the docs.

                    Comment


                      #11
                      I have tried setting saveLocally:false but it still doesn't send update requests to the server.

                      Comment


                        #12
                        Hi,

                        sorry for the delay in answering. We have committed a fix for this problem, that will be available in the next nightly build, could you please try it?

                        Comment


                          #13
                          Thank you.
                          I am going on vacation so I will not be able to test this for the next 3 weeks but I will take a look when I get back.

                          Comment

                          Working...
                          X