jvx

What is the difference between FilterEditor.setValue and FilterEditor.setDisplayValue


I am using a FilterEditor in one of my screens and i need to set an initial value to this filter.

What exactly is the difference between the methode setValue and setDisplayValue? Also in combination with the FilterType?

If i set the FilterType.EQUALS the filter is not correctly set with the methode setValue in my case. It works with setDisplayValue. If i set the FilterType.LIKE_IGNORE_CASE it is also working with setValue.


Solution

  • Normally the search value (get/setValue) and the display value (get/setDisplayValue) are the same.

    The only exception is, when the FilterEditor shows a combobox (ILinkedCellEditor) and the FilterType is EQUALS.

    In this case the FilterEditor searches directly the foreign key and not the joined display column, but shows the display column.

    So there is the possibility, to set the search value (setValue) or the display value (setDisplayValue). Using one of these functions will automatically set the according second value.

    eg:

    The table PROJECTS has a foreign key column STAT_ID to the table STATUS (ID, STATUS). The column STAT_STATUS will automatically be joined and preferred displayed.

    The table STATUS has the values (ID, STATUS): 1, created; 2, in progress; 3, closed; 4, cancelled;

    The FilterEditor editStatStatus is bound to the column STAT_STATUS with FilterType.EQUALS.

    You can now use editStatStatus.setValue("1") and "created" will be displayed, or you can use editStatStatus.setDisplayValue("created") and the search value will be set to "1".

    That means, that there is the flexibility, to set either the id or the status, but the FilterEditor will always show the display value and search for the foreign key value.

    Searching directly the foreign key is a way faster, because the query is much simpler for the database, and an index will be used, if one exists:

    SELECT ...
      FROM PROJECTS m
     WHERE m.STAT_ID = 1
    

    instead of searching the joined column:

    SELECT ...
      FROM PROJECTS m
           JOIN STATUS l1 ON l1.id = m.STAT_ID
     WHERE l1.STATUS = 'created'