I've following the instruction on jqGrid inline edit: odd behavior with an autocomplete column
But I've got wrong with it ...
I've already paste into :
{name:'SUPPLIERID', index:'SUPPLIERID', width:10, editable:true,align:'right',formatter: 'number', hidden: true},
{name:'SUPPLIER', index:'SUPPLIER', width:10, editable:true,edittype: 'text',
editoptions:{dataInit: function(elem) {
$(elem).autocomplete({
source: function(request, response) {$.getJSON("../../main/lookup/supplierExt.php", { q: request.term }, response)},
select: function(event, ui){
//alert (ui.item.SUPPLIERID);
var rowId = $("#g_terima").jqGrid('getGridParam', 'selrow');
var rowData = $("#g_terima").jqGrid('getRowData', rowId);
rowData.SUPPLIERID = ui.item.SUPPLIERID;
$("#g_terima").jqGrid('setRowData', rowId, rowData);
}
});
}}},
and our lookup Json :
<?php
session_start();
include($_SESSION[apppath].'modules/firebird.php');
$term = trim(strip_tags($_REQUEST['q']));
$sql = "select s.supplierid, c.contact supplier from supplier s
left join contact c on c.contactid = s.contactid
where s.companyid = $_SESSION[companyid] and c.contact like '%".$term."%'
order by c.contact ";
$stmt = $conn->query($sql);
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$row['id']=(int)$row[SUPPLIERID];
$row['SUPPLIERID']=(int)$row[SUPPLIERID];
$row['value']=htmlentities(stripslashes($row[SUPPLIER]));
$row['label']=htmlentities(stripslashes($row[SUPPLIER]));
$row_set[] = $row;
}
echo json_encode($row_set);
return true;
//exit();
?>
Autocomplete looks promising, but I can't passing ID / SUPPLIERID into SUPPLIERID COLUMN. Please is there something I make wrong ? I couldn't find it...
After pasting Oleg suggestion :
var g_terima = '#g_terima'; var pg_terima = '#pg_terima'; var file_terima = 'bip_terima_.php';
jQuery(document).ready(function(){
jQuery(g_terima).jqGrid({
url:file_terima,
editurl: file_terima,
datatype: 'json',
mtype: 'GET',
colNames:['Tgl','SUPPLIERID', 'Supplier', 'Internal','Peternak','Tipe', 'Produk', 'Jml/Berat', 'Harga','Total','PPN', 'Total+PPN'
, 'Inv No','Tax No','NoId'],
colModel :[
{name:'TGL', index:'TGL', width:9, editable:true,sorttype:'date',
editoptions:{
dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd',changeMonth: true,changeYear: true})}},
searchoptions:{dataInit:function(el){$(el).datepicker({dateFormat:'yy-mm-dd',changeMonth: true,changeYear: true})}}
},
{name:'SUPPLIERID', index:'SUPPLIERID', width:10, editable:true,align:'right',formatter: 'number', hidden: true},
{name:'SUPPLIER', index:'SUPPLIER', width:10, editable:true,edittype: 'text',
editoptions:{dataInit: function(elem) {
var $self = $(this);
$(elem).autocomplete({
source: function(request, response) {$.getJSON("../../main/lookup/supplierExt.php", { q: request.term }, response)},
select: function(event, ui){
//alert (ui.item.SUPPLIERID);
var rowId = $self.jqGrid('getGridParam', 'selrow');
$("#" + rowId + "_SUPPLIERID").val(ui.item.SUPPLIERID);
}
});
}}},
SUPPLIERID COLUMN still null value...