views:

314

answers:

1

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?

+2  A: 

Yes. The common auto-complete plugin does that - look at the "Multiple Birds (remote)" box, it searches for the first column but displays more data:

function formatItem(row) {
    return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}
function formatResult(row) {
    return row[0].replace(/(<.+?>)/gi, ''); //removes html tags
}
$("#suggest4").autocomplete('search.php', {
    width: 300,
    multiple: true,
    matchContains: true,
    formatItem: formatItem,
    formatResult: formatResult
});

The result of search.php?q=b is:

Great <em>Bittern</em>|Botaurus stellaris
Little Bittern|Ixobrychus minutus
American Bittern|Botaurus lentiginosus
Kobi