jquery - jqGrid autocomplete, select value and copy a value to another cell -
i'm working on project visual studio 2010 asp.net mvc4 , jqgrid. when deploying autocomplete , user selects value need copy value cell can solve problem? attached image , code.
this code, autocomplete works, how can copy value cell autocomplete?
jquery(document).ready(function () { var lastselection; jquery("#tbfacturacompra").jqgrid({ url: '@url.action("datosfacturacompra", "rafacturacompra", new { area = "operacion" })', editurl: '@url.action("datosfacturacompraabm", "rafacturacompra", new { area = "operacion" })', datatype: 'json', mtype: 'post', postdata: { idorden: idorden, partipoorden: partipoorden }, colnames: ['del', 'nit', 'factura', 'autorizacion', '', 'cod. control', 'fecha', 'importe', 'estado', '', ''], colmodel: [ { name: 'ac', width: 15, formatter: 'actions', formatoptions: { keys: true, editformbutton: false, delbutton: true, editbutton: false} }, { name: 'ofc_nit', index: 'ofc_nit', align: 'right', width: '50', editable: true, edittype: 'text', editoptions: { value : '', datainit: function (elem) { value: listarproveedores(elem); } } }, { name: 'ofc_nrofac', index: 'ofc_nrofac', align: 'right', width: '50', editable: true, edittype: 'text', editoptions: { style: "text-transform: uppercase"} }, { name: 'ofc_autorizacion', index: 'ofc_autorizacion', align: 'right', width: '50', editable: true, edittype: 'text', editoptions: { style: "text-transform: uppercase"} }, { name: 'ofc_alfanumerico', index: 'ofc_alfanumerico', editable: false, edittype: 'text', hidden: true }, { name: 'ofc_codigocontrol', index: 'ofc_codigocontrol', align: 'right', width: '50', editable: true, edittype: 'text', editoptions: { style: "text-transform: uppercase"} }, { name: 'ofc_fechafactura', index: 'ofc_fechafactura', align: 'center', width: '30', editable: true, formatter: 'date', formatoptions: { srcformat: "d-m-y", newformat: "d/m/y"} }, { name: 'ofc_importe', index: 'ofc_importe', align: 'right', width: '25', editable: true, formatter: 'number', formatoptions: { decimalplaces: 2} }, { name: 'ofc_parestadofaccom', index: 'ofc_parestadofaccom', width: '20', editable: true, edittype: "select", editoptions: { value: "v:v;f:f"} }, { name: 'ofc_partipoorden', index: 'ofc_partipoorden', editable: true, edittype: 'text', hidden: true }, { name: 'ofc_idordenpago', index: 'ofc_idordenpago', editable: true, edittype: 'text', hidden: true } ], pager: '#pg_tbfacturacompra', rownum: 15, rowlist: [15, 30, 45], sortname: 'ofc_fechafactura', sortorder: 'desc', viewrecords: true, rownumbers: true, imgpath: '/content/themes/base/images', multiselect: false, height: 170, width: 700, footerrow: true, grid: true, toolbar: [true, "top"], loadcomplete: function (data) { var id = $.jgrid.randid(); var $grid = $('#tbfacturacompra'); var mydata = [{ ofc_nit: "", ofc_nrofac: "", ofc_autorizacion: "", ofc_alfanumerico: "-.-", ofc_codigocontrol: "", ofc_fechafactura: fechaserv, ofc_importe: "0.0", ofc_parestadofaccom: "v", ofc_partipoorden: partipoorden, ofc_idordenpago: idorden}]; $grid.jqgrid('addrowdata', id, mydata[0], "first"); $grid.jqgrid("editrow", id, true, '', '', '', '', reload); }}); });
update oleg code contains jquery ui autocomplete: in return value "autorizacion" id: item.ofr_ultimaauto in autocomplete function "listaproveedores" value of "autorizacion" item.id form fast filling of bills (taxes) grid not searching toolbar. when select value autocomplete how can copy id: item.ofr_ultimaauto column "autorizacion"?
function getdata(request, response) { $.ajax({ url: '@url.action("buscarazonsocial", "rafacturacompra", new { area = "operacion" })', type: 'get', datatype: 'json', data: { term: request.term, maxresult: 20 }, success: function (data) { response($.map(data, function (item) { return { label: item.ofr_nit, value: item.ofr_nit, id: item.ofr_ultimaauto, desc: item.ofr_razon }; })) } }); } function listarproveedores(elem) { $(elem).autocomplete({ source: getdata, minlength: 5, autosearch: true, select: function (event, ui) { $(elem).val(ui.item.value); $(elem).focus().trigger({ type: 'keypress', charcode: 13 }); } }).data("ui-autocomplete")._renderitem = function (ul, item) { return $("<li>") .append("<a class='ui-menu-item-titulo'><strong>" + item.label + "<br>" + item.desc + " - </strong>" + item.id + "</a>") .appendto(ul); }; }
the code posted don't contains call of jquery ui autocomplete. can't point exact place of code can extent. nevertheless try explain can do. typically 1 call $(elem).autocomplete
inside of datainit
. jquery ui autocomplete supports select
callback (see here example) can use set new value in autorizacion
column. use name: 'ofc_autorizacion'
column. id
of input field of searching toolbar gs_ofc_autorizacion
, can access $("#gs_ofc_autorizacion").val("5031124051");
. data returned server jquery ui autocomplete in format array of objects (for example array of objects properties value
, autorizacion
) can find same properties in ui.item
. can simplify code. hope understand mean.
updated: see line above of grid not searching toolbar, inline editing. use var id = $.jgrid.randid();
id of first row. id of input field has id + "_ofc_autorizacion"
instead of "gs_ofc_autorizacion"
.
Comments
Post a Comment