Jquery jqGrid自动完成,选择值并将值复制到另一个单元格

Jquery jqGrid自动完成,选择值并将值复制到另一个单元格,jquery,jqgrid,Jquery,Jqgrid,我正在使用VisualStudio2010ASP.NETMVC4和jqGrid进行一个项目。 当部署autocomplete并且用户选择一个值时,我需要将一个值复制到另一个单元格,就像我可以解决这个问题一样?我附上了一张图片和代码。 这是我的代码,自动完成功能,如何将值从自动完成复制到另一个单元格 jQuery(document).ready(function () { var lastSelection; jQuery("#tbFacturaCompra").jqGrid({

我正在使用VisualStudio2010ASP.NETMVC4和jqGrid进行一个项目。 当部署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);
        }});
});
更新 Oleg这是包含Jquery UI自动完成的代码: 在返回值中,Autorizacion的值为id:item.ofr\u ultimauto,在自动完成函数列表中,Autorizacion的值为item.id 此表格用于快速填写税单 网格不是来自搜索工具栏。从“自动完成”中选择值时,如何将id:item.ofr_ultimauto复制到列自动生成


您发布的代码不包含任何jQueryUIAutoComplete调用。所以我不能给你们指出代码的确切位置,你们可以扩展它。然而,我试图解释你能做什么。通常在dataInit内部调用$elem.autocomplete。jQueryUIAutoComplete支持选择回调。请参阅一个示例,您可以使用该示例在Autorization列中设置新值。您可以在列中使用名称:“ofc_Autorization”。因此,搜索工具栏的输入字段的id是gs_of c_autorization,您可以通过$gs_of c_autorization.val5031124051;访问它;。如果jQuery UI Autocomplete服务器返回的数据采用对象数组的格式,例如带有属性值和Autorization的对象数组,那么您可以在UI.item中找到相同的属性。它可以简化您的代码。我希望你明白我的意思


更新:我看到网格上方的线条不是来自搜索工具栏,而是来自内联编辑。使用var id=$.jgrid.randId;作为第一行的id。因此,输入字段的id将是id+_ofc_Autorization,而不是gs_ofc_Autorization。

我已经用代码autocomplete更新了我的问题,我希望您能帮助我?@raranibar:因为ofc_Autorization列具有editable:true属性,可编辑行应该包含其中123是rowid,您可以在Autocomplete的select回调中找到它$elem.closesttr.attrid。因此,您可以将select回调修改为以下select:函数事件,ui{$elem.valui.item.value;$elem.closesttr.findinput[name=ofc_autorization].valui.item.id;$elem.focus.trigger{type:keypress,charCode:13};}
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);
    };  
}