Autocomplete with id and name search

Asked

Viewed 211 times

1

How can I make an autocomplete with search in two columns of the database?

I’ve looked at several examples, and I’ve seen one that uses a kind of grid, it’s like $("#seletor").combogrid(...).

I’ve already managed to implement my autocomplete but only does the search by Article name and I would like you to also do the search by id.

HTML

<input class="codigo autoC" type="text" placeholder="Nome ou Código do Artigo">

JQUERY

//Pedido ajax que retorna a lista dos artigos   

    myJSRoutes.controllers.c_base.c_artigos.ArtigoController.getAllArtigos().ajax({
       success: function (data) {
         if (data.length > 0) {
           $.each(data, function (key, value) {
             artigos.push(value.nome);
           });
         }
       }
    })

//AUTOCOMPLETE
    $(document).on('click', '.autoC', function () {
        $(".autoC").autocomplete({
            source: artigos,
            //REMOVE UM SPAN ADICIONADO AUTOMATICAMENTE AO GERAR O AUTOCOMPLETE
            create: function (e) {
                $(this).prev('.ui-helper-hidden-accessible').remove();
            }
        });
    })

Any suggestions on how to search by id and name?

  • Could you please put your filter code?

  • Sorry I didn’t get the point. Everything I have related to my autocomplete is in the question. Maybe something is missing but...is all I have in my code. Thanks in advance

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.