Autocomplete - Filter with empty string on arrow keys and focus

Hi Team,

I am unable to trigger filter event on focus and arrow key function with empty string. Need to call API call on pressing arrow keys or onfocus

Requirement: User should be able to see autocomplete results with empty string by pressing arrow keys or focusing autocomplete.


  1. Autocomplete component
  2.                   <ejs-autocomplete
                        :dataSource="outletsOptions"
                        cssClass="autoCompleteClass"
                        :filtering="getOutlets"
                        :value="selectedOutletName"
                        @change="selectOutlet"
                        ref="outletAutocomplete"
                      ></ejs-autocomplete>
  3. Filtering event
  4. getOutlets(searchText) {
          const client = api()
          client
            .get('/customer', {
              params: {
                maxRows: 100,
                ...(this.selectedSalesman ? { SalesmanID: this.selectedSalesman } : {}),
                term: searchText.text ? searchText.text : 'all',
                autotext: searchText.text ? searchText.text : 'all',
                _: new Date().getTime()
              }
            })
            .then(response => {
              if (response.data.CustomerMaster && response.data.CustomerMaster.length > 0) {
                let optionArray = []
                response.data.forEach(item => {
                  let option = { id: ''text: '' }
                  option.id = item.CustomerID
                  option.text = item.CustomerName + '(' + item.CustomerCode + ')'
                  optionArray.push(option)
                })
                this.outletsOptions = [...optionArray]
              }
            })
            .catch(error => {
              console.error(error'Unable to search division')
            })
        },
  5. Response from API call
  6. {

      "CustomerMaster": [

        {

          "CustomerID": 11718,

          "CustomerCode": "0500732349",

          "CustomerName": "SHREE SHRIJI NASTA HOUSE",

          "CustomerNameCode": "SHREE SHRIJI NASTA HOUSE (0500732349)",

          "CustomerPaymentType": 1,

          "SalesMode": 0,

          "PromotionControl": "1",

          "CustomerState": 12,

          "DistributorState": 1,

          "CustomerStateType": 0,

          "DistributorStateType": 0,

          "BillToCustomer": ""

        },

        {

          "CustomerID": 11730,

          "CustomerCode": "0500733131",

          "CustomerName": "SHIVAM DAIRY",

          "CustomerNameCode": "SHIVAM DAIRY (0500733131)",

          "CustomerPaymentType": 1,

          "SalesMode": 1,

          "PromotionControl": "1",

          "CustomerState": 12,

          "DistributorState": 1,

          "CustomerStateType": 0,

          "DistributorStateType": 0,

          "BillToCustomer": ""

        }

      ]

    }


3 Replies 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team August 31, 2021 12:52 PM UTC

Hi Sandeep, 


Greetings from Syncfusion support.  


We can trigger the filtering event manually by calling the searchLists method wherever needed. Refer the following code. 


  onFocus: function (args) { 
      this.$refs.autoComplete.ej2Instances.searchLists(args.event); 
    }, 



Please find the sample below. 


Kindly get back to us for further assistance. 

Regards, 
Sevvandhi N 



SG Sandeep G September 1, 2021 06:22 AM UTC

Hi Sevvandhi,

Thanks for you reply. Changed to same method on focus event. It worked.

<ejs-autocomplete
                    :dataSource="outletsOptions"
                    cssClass="autoCompleteClass"
                    :filtering="getOutlets"
                    :value="selectedOutletName"
                    @change="selectOutlet"
                    :focus="getOutlets"
                    ref="outletAutocomplete"
                  ></ejs-autocomplete>

How to show list of results on focus? before user press arrow keys



SN Sevvandhi Nagulan Syncfusion Team September 2, 2021 01:35 PM UTC

Hi Sandeep, 


We checked your query. We can show the popup using showPopup public method. Kindly refer the below code. 

    onFocus: function(args) 
    { 
        if ( this.$refs.autoComplete.ej2Instances.value == "" || this.$refs.autoComplete.ej2Instances.value == null ) { 
            this.$refs.autoComplete.ej2Instances.showPopup(); 
        } else 
        { 
            this.$refs.autoComplete.ej2Instances.searchLists(args.event); 
        } 
    } 


Please find the sample below. 


Kindly get back to us for further assistance. 

Regards, 
Sevvandhi N 


Marked as answer
Loader.
Up arrow icon