Announcement

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

    Filtering columns in non-datasource-grouped grids

    Hello there,

    I'm stuck with an issue using filters in columns in a grouped ListGrid.

    The grid was created this way:

    Code:
    vehicleFenceGrid = new ListGrid();
    vehicleFenceGrid.setHeight100();
    vehicleFenceGrid.setWidth100();
    vehicleFenceGrid.setFixedRecordHeights(true);
    vehicleFenceGrid.setCellHeight(32);
    vehicleFenceGrid.setMargin(5);
    vehicleFenceGrid.setBorder("1px solid " + BORDER_COLOR);
    vehicleFenceGrid.setAutoFetchData(false);
    vehicleFenceGrid.setSelectionAppearance(SelectionAppearance.ROW_STYLE);
    vehicleFenceGrid.setSelectionType(SelectionStyle.MULTIPLE);
    vehicleFenceGrid.setCanMove(true);
    vehicleFenceGrid.setGroupByField(VehicleFenceConstants.VEHICLE_ID);
    vehicleFenceGrid.setCanUpdate(true);
    vehicleFenceGrid.setFilterLocalData(true);
    vehicleFenceGrid.setDataFetchMode(FetchMode.LOCAL);
    The columns set like this:

    Code:
    private void setVehicleFenceGridFields() {
            idGridField = new ListGridField(SimpleListGrid.GRID_ID_FIELD);
            idAssociationField = new ListGridField(FenceConstants.ID);
            idAssociationField.setHidden(true);
            
            vehicleIdAssociationField = new ListGridField(VehicleFenceConstants.VEHICLE_ID);
            vehicleIdAssociationField.setHidden(true);
    
            vehicleNameAssociationField = new ListGridField(HistoryEntryFieldsConstants.FIELD_VEHICLE_NAME);
            vehicleNameAssociationField.setHidden(true);
    
            vehiclePlateAssociationField = new ListGridField(HistoryEntryFieldsConstants.FIELD_VEHICLE_LICENSE_PLATE);
            vehiclePlateAssociationField.setHidden(true);
            
            isOrderedField = new BooleanListGridField(VehicleFenceConstants.FENCE_ORDERED, CONSTANTS.sortable());
            isOrderedField.setCanToggle(true);
            vehicleFenceGrid.setBooleanTrueImage(null);
            vehicleFenceGrid.setBooleanFalseImage(null);
            isOrderedField.setCanFilter(false);
            isOrderedField.setWidth("20%");
            
          [B]  // editor config[/B]
    [B]        userEmailAssociationField = new ListGridField(UserPortalOrionFieldsConstants.USER_EMAIL_ID,
                    CONSTANTS.userEmail());
            userEmailAssociationField.setRequired(false);
            userEmailAssociationField.setSortByDisplayField(true);
            SelectItem userEmailSelectItem = new SelectItem();
            userEmailSelectItem.setAllowEmptyValue(true);
            
            userEmailAssociationField.setEditorProperties(userEmailSelectItem);
            userEmailAssociationField.setCanEdit(true);[/B]
    
    [B]        // filter config
            userEmailAssociationField.setFilterOnKeypress(true);
            userEmailAssociationField.setCanFilter(true);
            userEmailAssociationField.setFilterEditorProperties(new SelectItem());
            userEmailAssociationField.setFilterEditorValueMap(userMap);[/B]
            
            fenceTypeAssociationField = new ListGridField(VehicleFenceConstants.FENCE_TYPE, "fenceType");
            fenceTypeAssociationField.setHidden(true);
    
            fenceWebAssociationField = new ListGridField(VehicleFenceConstants.FENCE_WEB, "fenceWeb");
            fenceWebAssociationField.setHidden(true);
    
            fenceClientAssociationField = new ListGridField(VehicleFenceConstants.CLIENT_ID, "clientId");
            fenceClientAssociationField.setHidden(true);
    
            fenceMacroGroupAssociationField = new ListGridField(VehicleFenceConstants.FENCE_MACRO_GROUP, "MacroGroupId");
            fenceMacroGroupAssociationField.setHidden(true);
    
            nameAssociationField = new ListGridField(VehicleFenceConstants.FENCE_NAME, CONSTANTS.name());
            [B]nameAssociationField.setCanFilter(true);[/B]
            nameAssociationField.setCanEdit(false);
            nameAssociationField.setWidth("40%");
    
            fencePriorityAssociationField = new ListGridField(VehicleFenceConstants.FENCE_PRIORITY,
                    CONSTANTS.fencePriority());
            fencePriorityAssociationField.setAlign(Alignment.LEFT);
            fencePriorityAssociationField.setWidth("15%");
            fencePriorityAssociationField.setCanSort(false);
            fencePriorityAssociationField.setCanFilter(false);
            fencePriorityAssociationField.setCanEdit(false);
            fencePriorityAssociationField.setCellFormatter(new CellFormatter() {
                @Override
                public String format(Object value, ListGridRecord record,
                        int rowNum, int colNum) {
                    String result = "";
    
                    if (value != null) {
                        int priorityCode = Integer.parseInt(value.toString());
                        result = FencePriorityValueMapProvider.getValueMap().get(
                                priorityCode);
                    }
                    return result;
                }
            });
    
            vehicleFenceGrid.setFields(idGridField, vehicleIdAssociationField,
                    vehicleNameAssociationField, vehiclePlateAssociationField,
                    isOrderedField, userEmailAssociationField, nameAssociationField,
                    fencePriorityAssociationField, /* shapeAssociationField , colorAssociationField , */
                    idAssociationField/* , groupAssociationField */);
        }
    One of the problems is with de code in bold (userEmailAssociationField). The combobox appears in the filter place, but it doesn´t show the items such as in the cells itself (sometimes it does, though). I'm using the same static LinkedHashMap for both. Another situation is that the grid won´t filter when for instance the user enters a text in nameAssociationField. Is that due to the grid is grouped by another column?

    Any help?

    Thanks a lot.

    #2
    Try setting the valueMap on the SelectItem in userEmailAssociationField.setFilterEditorProperties(new SelectItem()), meaning create an SelectItem object and use that instead of setFilterEditorValueMap().
    I have a similar setup working for me (without your setFilterOnKeypress()).

    For the other text-filtering issue I have no idea. It should work IMHO. You can set a different category value for ListGrid filtering in the Developer Console and try to understand what (not) happens why.

    Best regards
    Blama

    Comment


      #3
      Just to make it official: Blama's advice for where to set the valueMap is correct.

      As far as filtering, this grid does not appear to have a DataSource, which is required for filtering - you should see a message in your Developer Console telling you this, so be sure to check that regularly while coding. See also listGrid.filterLocalData.

      Comment


        #4
        Originally posted by Blama View Post
        Try setting the valueMap on the SelectItem in userEmailAssociationField.setFilterEditorProperties(new SelectItem()), meaning create an SelectItem object and use that instead of setFilterEditorValueMap().
        I have a similar setup working for me (without your setFilterOnKeypress()).

        For the other text-filtering issue I have no idea. It should work IMHO. You can set a different category value for ListGrid filtering in the Developer Console and try to understand what (not) happens why.

        Best regards
        Blama
        You're rigth man. That solved the problem. Thanks a lot.

        Best regards.

        Comment


          #5
          Originally posted by Isomorphic View Post
          Just to make it official: Blama's advice for where to set the valueMap is correct.

          As far as filtering, this grid does not appear to have a DataSource, which is required for filtering - you should see a message in your Developer Console telling you this, so be sure to check that regularly while coding. See also listGrid.filterLocalData.
          Yes, the grid hadn't been created with a client only datasource. Once it bound to the grid, everything started working as expected.

          Thank you.

          Best.

          Comment

          Working...
          X