Repository: pimcore/pimcore (language: php)

Issue:
[Custom Reports] Filter dropdowns are not filtered by the typed in phrase
# Bug Report
  
### Expected behavior 
- elements in the dropdown field should be filtered by typed in phrase

Nice to have
- if I type in one of the correct elements and press enter, it should filter the documents list
- empty entry in the dropdown list should be named

### Actual behavior  
- still all elements are visible, dropdown list is not filtered by typed in phrase
- when you have a lot of entries in this list, this in not usable
- if you type in one of the correct elements and press enter, the whole documents list is loaded, because there is an empty entry in the dropdown list, which is not named and this is then selected
  
### Steps to reproduce  
- create Custom Report with SQL
  - SELECT id, type
  - FROM documents
  - Column Configuration for type
    - Filter Drilldown -> Filter and Show
- save and let reload
- got to the created custom report
  - click in the filter selectbox for type
  - type in 'link'
  
### further information
- it is also reproducable in the Version 4.6.3

![image](https://user-images.githubusercontent.com/38213550/38497225-a5bda346-3c00-11e8-9f02-c3350277bc6c.png)




Discussion / hints:
IMHO, it seems that you accidentally selected the first "empty" entry which is a bit unfortunate regarding optical aspects. Please try to specifically select one of the dropdown entries.
@weisswurstkanone 
I have not selected anything. That is the value that is selected by default after I entered the 'link' text. That is exactly one of the issues I have reported here.
When I click one of the dropdown entries the list is filtered correctly.
And in the image you can see, that the list in not filtered by my given 'link' text. If I have over 100 entries in this list, it is not usable.
Still is an issue in Version 5.4.2
is this still an issue? or is it fixed? 
Hi @fashxp,
I can still reproduce the complete bug report in the new demo version.
![image](https://user-images.githubusercontent.com/38213550/67760463-ac2d9f00-fa41-11e9-9450-822472d29b04.png)
Greetings Kerstin

Thanks a lot for reporting the issue. The issue was not considered by us as "Priority" or "Backlog", so we're not gonna work on that anytime soon. In case this is a bug report, please create a pull request fixing the issue, we'll then review it as soon as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request, we'll then decide whether we'd accept it or not. Thanks for your understanding.

Currently it is the case that on the backend side an empty first option is passed. This leads to the incorrect behavior described. I assume.
As can be seen in this example response from Pimcore\Bundle\AdminBundle\Controller\Reports\CustomReportController: 
![Bildschirmfoto 2022-06-21 um 17 47 56](https://user-images.githubusercontent.com/93768325/174844604-815ab0fc-753b-4681-88da-e4c5e371eecc.png)

Is this intended in this case to reset the filter? 
For an improved user experience, i could add a button to reset the filter (like so:) 
![Bildschirmfoto 2022-06-21 um 17 59 42](https://user-images.githubusercontent.com/93768325/174845647-6db507da-d334-472c-975b-a1f00e7ea753.png)

I am currently not sure in which places this filter is used in this way. Before I can create a PR on this topic, I need feedback on this issue because of possible side-effects.



Fix patch:
diff --git a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js
index 663a3c68f8f..74f28e3f2fa 100644
--- a/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js
+++ b/bundles/CustomReportsBundle/public/js/pimcore/report/custom/report.js
@@ -282,18 +282,26 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr
                 store: drillDownStore,
                 listeners: {
                     select: function(fieldname, combo, record, index) {
-                        var value = combo.getValue();
+                        let value = combo.getValue();
+
+                        const lastQuery = combo.lastQuery;
+                        // check last query
+                        if(value == null && lastQuery && this.store.findExact(fieldname, lastQuery)) {
+                            value = lastQuery;
+                            combo.setValue(value)
+                        }
+
                         this.drillDownFilters[fieldname] = value;
 
-                        var proxy = this.store.getProxy();
+                        const proxy = this.store.getProxy();
                         proxy.extraParams['drillDownFilters[' + fieldname + ']'] = value;
                         if(this.chartStore) {
-                            var chartProxy = this.chartStore.getProxy();
+                            let chartProxy = this.chartStore.getProxy();
                             chartProxy.extraParams['drillDownFilters[' + fieldname + ']'] = value;
                         }
-                        for(var j = 0; j < this.drillDownStores.length; j++) {
+                        for(let j = 0; j < this.drillDownStores.length; j++) {
                             if(this.drillDownStores[j] != combo.getStore()) {
-                                var drillDownProxy = this.drillDownStores[j].getProxy();
+                                let drillDownProxy = this.drillDownStores[j].getProxy();
                                 drillDownProxy.extraParams['drillDownFilters[' + fieldname + ']'] = value;
                             } else {
                                 this.drillDownStores[j].notReload = true;
@@ -304,7 +312,7 @@ pimcore.bundle.customreports.custom.report = Class.create(pimcore.bundle.customr
                     }.bind(this, this.drillDownFilterDefinitions[i]["name"])
                 },
                 valueField: 'value',
-                displayField: 'value'
+                displayField: 'name'
             });
             if(i < this.drillDownFilterDefinitions.length-1) {
                 drillDownFilterComboboxes.push('-');
diff --git a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php
index be841ddbc3e..2c91bfca805 100644
--- a/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php
+++ b/bundles/CustomReportsBundle/src/Tool/Adapter/Sql.php
@@ -212,14 +212,14 @@ public function getAvailableOptions(array $filters, string $field, array $drillD
         $filteredData = [];
         foreach ($data as $d) {
             if (!empty($d[$field]) || $d[$field] === 0) {
-                $filteredData[] = ['value' => $d[$field]];
+                $filteredData[] = ['name' => $d[$field], 'value' => $d[$field]];
             }
         }
 
         return [
             'data' => array_merge(
                 [
-                    ['value' => null],
+                    ['name' => 'empty', 'value' => null],
                 ],
                 $filteredData
             ),


Test patch: