mardi 25 août 2015

Fetch data from sqlite and display it in autocomplete

I'm working for iPhone application using phonegap. In the application there are few dropdowns whose values are more the 10000. Now we are trying to replace the dropdown with Autocomplete.

We are maintaining those 10000 records in SQLite DB and fetch the records from the DB as user enters the string.

CODE:

<input type ="text" class="inputFormText" ng-model="Location.location" id="location" list ="locValues" placeholder="{{'lSummary_Location_text'|translate}}"  autocomplete = "on" maxlength="80" ng-keyup="populateLocations($event)"/>

            <div class="aListCon">
                <datalist id="locValues">

                </datalist>
            </div>

$scope.populateLocations = function($event){

              if ($event.target.value.length > 2) {
                    try
                    {
                          db.transaction(function(tx){
                                tx.executeSql("SELECT ID, VALUE FROM tbl_Location WHERE VALUE LIKE '%" + $event.target.value + "%'", [], 
                                      function(tx, res){

                                            if(res.rows.length > 0)
                                            {
                                                  var template = "";
                                                  for (var i = 0; i < res.rows.length; i++) {


                                                        var id = res.rows.item(i).value + ' / ID: ' + res.rows.item(i).id;
                                                        template += '<option class="aCon" id="' + id + '" value="' + res.rows.item(i).value + '"></option>';
                                                  };

                                                  document.getElementById('locValues').innerHTML = template;
                                            }
                                            else
                                                console.log("No records found")  
                                      },
                                      function(ex){
                                            console.log("Populate Location Error: " + ex.message);
                                      });
                          });
                    }
                    catch(ex)
                    {
                          console.log("Populate Location Error: " + ex.message);
                    }
              };
        };

I was able to fetch the records form the SQLite and append to the datalist, but Autocomplete is not displayed in the UI.

Any idea where I'm going wrong?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire