Announcement

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

    Setting "in" criteria for grid filter

    Hi,
    I have a grid with some list data. One of the field is status (active, inactive, test).

    <field name="status" type="enum" title="Status" required="true"
    length="2">
    <valueMap>
    <value ID="A">Active</value>
    <value ID="I">Inactive</value>
    <value ID="T">Test</value>
    <value ID="T,I">Test - Inactive </value>
    </valueMap>
    </field>

    I added the last value as so I can do an "in" for the criteria.

    Is this doable? If I set the filter operator as below?

    statusField.setFilterOperator(OperatorId.IN_SET);

    #2
    That's not quite going to work because you've just got a String with value "T,I" not an Array of values, which is what would cause filtering where any value would match. Instead, use the change handler to set the value of the "status" FormItem to an Array of Strings ([T,I]).

    Comment


      #3
      Here is what showing in my request.

      {
      "dataSource":"esd_install_suite",
      "operationType":"fetch",
      "componentId":"isc_ESDAbstractPanel_1_0",
      "data":{
      "operator":"and",
      "criteria":[
      {
      "fieldName":"status",
      "operator":"inSet",
      "value":"T,I"
      }
      ]
      },
      "startRow":0,
      "endRow":75,
      "sortBy":[
      "status",
      "name"
      ],
      "textMatchStyle":"substring",
      "resultSet":[ResultSet ID:isc_ResultSet_0 (created by: isc_ESDAbstractPanel_1_0)],
      "callback":{
      "caller":[ResultSet ID:isc_ResultSet_0 (created by: isc_ESDAbstractPanel_1_0)],
      "methodName":"fetchRemoteDataReply"
      },
      "willHandleError":true,
      "showPrompt":false,
      "prompt":"Finding Records that match your criteria...",
      "oldValues":{
      "operator":"and",
      "criteria":[
      {
      "fieldName":"status",
      "operator":"inSet",
      "value":"T,I"
      }
      ]
      },
      "clientContext":{
      "requestIndex":6
      },
      "requestId":"esd_install_suite$62717"
      }

      Comment


        #4
        I tried add this but it does not seem like the filter change it firing the event?

        statusField.addChangedHandler(new com.smartgwt.client.widgets.grid.events.ChangedHandler() {

        @Override
        public void onChanged(
        com.smartgwt.client.widgets.grid.events.ChangedEvent event) {
        System.err.println("????????????????KKKKKKKK" + event.getValue());

        }
        });

        Comment


          #5
          Wrong object, apply the Changed handler to the FormItem used for filtering via setFilterEditorType(). The handler you've added would only for edits in the body of the grid (as documented).

          Comment


            #6
            I got the changedEvent to fire. However, the filter event is not firing?

            LinkedHashMap<String , String> valueMap = new LinkedHashMap<String, String>();
            valueMap.put("A", "<b>Active</b>");
            valueMap.put("I", "<b>Inactive</b>");
            valueMap.put("T", "<b>Test</b>");
            valueMap.put("T,I", "Test - Inactive");


            final SelectItem statusFilter = new SelectItem();
            statusFilter.setValueMap(valueMap);

            statusFilter.addChangedHandler(new ChangedHandler() {
            @Override
            public void onChanged(ChangedEvent event) {
            System.err.println("??????? "+ event.getValue());
            }
            });


            statusField.setFilterEditorType(statusFilter);

            Comment


              #7
              Hi,
              I changed the event and it is now firing the filter event but I am not sure what I need to change to affect the filter value?


              [CODE]
              final ListGridField statusField = new ListGridField("status",
              ApplicationController.getInstance().getConstant()
              .theStatus(), 50);


              statusField.setFilterOperator(OperatorId.IN_SET);

              LinkedHashMap<String , String> valueMap = new LinkedHashMap<String, String>();
              valueMap.put("A", "<b>Active</b>");
              valueMap.put("I", "<b>Inactive</b>");
              valueMap.put("T", "<b>Test</b>");
              valueMap.put("T,I", "Test - Inactive");

              final SelectItem statusFilter = new SelectItem();
              statusFilter.setValueMap(valueMap);

              statusFilter.addChangeHandler(new ChangeHandler() {

              @Override
              public void onChange(ChangeEvent event) {
              if ("T,I".equalsIgnoreCase(event.getValue().toString())){
              String[] v = {"T", "I"};
              // what to set here???
              }
              }
              });


              statusField.setFilterEditorType(statusFilter);

              [CODE]

              Comment


                #8
                event.getItem().setValue()

                Comment


                  #9
                  That throw a JavaScript Error. It is not liking the string array.

                  [CODE]

                  String[] v = {"T", "I"};
                  event.getItem().setValue(v);

                  [CODE]

                  But this seem to work.

                  [CODE]

                  String[] v = {"T", "I"};
                  Criteria c = new Criteria();
                  c.addCriteria("status", v);

                  [CODE]

                  Comment

                  Working...
                  X