Define options as value/ label pairs.
var ships = [
{ "value": "", "label": "" },
{ "value": "SE", "label": "Speedy Express" },
{ "value": "UP", "label": "United Package" },
{ "value": "FS", "label": "Federal Shipping" }
];
Define the autoComplete to accomodate 2 fields.
function autoCompleteEditor( source, di ) {
return function (ui) {
ui.$cell.addClass('ui-front');//so that dropdown remains with input.
//initialize the editor
ui.$editor.autocomplete({
source: source,
position: {
collision: 'flipfit',
within: ui.$editor.closest(".pq-grid")
},
select: function (event, ui2) {
ui.$editor.val( ui2.item.label ); // display the selected text
ui.rowData[di] = ui2.item.value; // save selected id to hidden input
return false;
},
minLength: 0
}).focus(function () {
//open the autocomplete upon focus
$(this).autocomplete("search", "");
});
}
}
Then define columns in colModel.
{ dataIndx: 'ShipViaId', hidden: true }, //hidden column to store ShipVia Id.
{
title: "Shipping Via", dataIndx: "ShipVia", width: 110,
cls: 'pq-dropdown pq-side-icon',
editor: {
type: 'textbox',
init: autoCompleteEditor(ships, 'ShipViaId' )
}
},