Author Topic: Autocomplete for multiple columns  (Read 2618 times)

engmag

  • Newbie
  • *
  • Posts: 4
    • View Profile
Autocomplete for multiple columns
« on: November 09, 2016, 05:02:08 am »
Hi, I am using Autocomplete from the following example:  http://paramquery.com/pro/demos/editing_custom and wants to add support for many columns.

The code below supports column books and the countries. How can I add more local? Say that I have two columns (books, author) and I have one variable for each containing the values for Autocomplete.

It seems like the source can be defined in a dynamic way, but how does that syntax work?

Code: [Select]
source: (ui.dataIndx == "books" ? books : "/pro/demos/getCountries")
Can I add this to the same function below or is it recomended to add a separate function for each column?



 
Code: [Select]
       var autoCompleteEditor = function (ui) {
            var $inp = ui.$cell.find("input");

            //initialize the editor
            $inp.autocomplete({
                source: (ui.dataIndx == "books" ? books : "/pro/demos/getCountries"),
                selectItem: { on: true }, //custom option
                highlightText: { on: true }, //custom option
                minLength: 0
            }).focus(function () {
                //open the autocomplete upon focus               
                $(this).autocomplete("search", "");
            });
        }

BR

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Autocomplete for multiple columns
« Reply #1 on: November 09, 2016, 09:50:00 am »
Of course more than one column can use same autoComplete editor definition.

if( ui.dataIndx == di1 ){
  source = source1
}
else if( ui.dataIndx == di2 ){
  source = source2;
}
else if( condition.. ){
  so on...
}

$inp.autocomplete({
       source: source,
       ...
})

engmag

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Autocomplete for multiple columns
« Reply #2 on: November 10, 2016, 11:16:56 pm »
Thanks!