Is there a smart way to ensure that IDs are set when selecting names with autocomplete?
var autoCompleteEditor_StationGroups = function (ui) {
let $inp = ui.$cell.find("input"),
rIndx = ui.rowIndx,
rData = ui.rowData,
grid = this;
$inp.autocomplete({
source: function(req, res) {
res(station_groups.filter(function(item, index) {
return (item.value).indexOf(req.term) >= 0;
}));
},
selectItem: { on: true },
highlightText: { on: true },
autoFocus: true,
delay: 250,
minLength: 1,
change: function(evt, ui) {
rData.id = ui.item.id; // <- 1. Dirty does not arrive.
grid.updateRow({ rowIndx: rIndx, newRow: { "id": ui.item.id }}); // <- 2. Dirty does not arrive.
grid.refreshCell({ rowIndx: rIndx, dataIndx: "id" });
}
}).focus(function () {
//open the autocomplete upon focus
$(this).autocomplete("search", "");
});
}
{ title: "ID", dataIndx: "id", editable: false, minWidth: 80, maxWidth: 80, align: "center", cls: "pq-col-editable-false" },
{ title: "Name", dataIndx: "name", dataType: "string", minWidth: 160, maxWidth: 160,
editor: {
type: "textbox",
init: autoCompleteEditor_StationGroups,
// mapIndices: { "id": id, "name": name } // 3. <- Become an error.
},
editModel: { keyUpDown: false },
// getData: function (ui) {
// this.refreshCell({ rowIndx: rIndx, dataIndx: "station_group_id" });
// postRender: function (ui) {
// this.refreshCell({ rowIndx: ui.rowIndx, dataIndx: "station_group_id" });
// }
},
1. 2. 3. None of them was useless.