Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-column Autocomplete for jQuery?

Is there an AJAX autocomplete for jQuery that supports multiple columns? I mean multiple columns like a database table, not just splitting a list up. It would search off the first column, but the rest would be visible in the dropdown.

Does such a thing exist?

like image 481
Xavin Avatar asked Apr 15 '10 21:04

Xavin


1 Answers

try this code searching for one column but displaying multiple columns 
$(function() {
    $(".tb").autocomplete
            ({
                source: function(request, response) {
                    $.ajax({
                        type: "POST",
                        url: "WebService_GetData.asmx/GetCmbPostaKod",
                        dataType: "json",
                        data: "{ 'filterKey': '" + request.term + "' }",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function(data) { return data; },
                        success: function(data) {
                            response($.map(data.d, function(item) {
                            return { value: item.PostaKodu, label: item.IlAdi + ' ' + item.IlceAdi + ' ' + item.SemtAdi + ' ' + item.PostaKodu }
                            }))
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
                        }
                    });
                },
                minLength: 2,
                multiple: true,
                matchContains: true,
                formatItem: formatItem,
                formatResult: formatResult
            });
        });

        function formatItem(row) {
            return row[0] + " (<strong>id: " + row[1] + "</strong>)";
        }
        function formatResult(row) {
            return row[0].replace(/(<.+?>)/gi, ''); //removes html tags
        }
like image 200
Altan Alansu Avatar answered Oct 16 '22 15:10

Altan Alansu