【问题标题】:jqGrid autocomplete, select value and copy a value to another celljqGrid自动完成,选择值并将值复制到另一个单元格
【发布时间】:2013-08-23 18:02:35
【问题描述】:

我正在使用 Visual Studio 2010 Asp.Net MVC4 和 jqGrid 开发一个项目。 当部署自动完成并且用户选择一个值时,我需要将一个值复制到另一个单元格,因为我可以做些什么来解决这个问题?我附上了一张图片和代码。

这是我的代码,自动完成功能有效,如何将值从自动完成复制到另一个单元格?

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_ultimaauto 在自动完成函数“ListaProveedores”中“Autorizacion”的值 item.id 此表格用于快速填写账单(税金) 网格不是来自搜索工具栏。从自动完成中选择值时,我如何将 id: item.ofr_ultimaauto 复制到“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);
    };  
}

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    您发布的代码不包含任何 jQuery UI 自动完成调用。所以我不能指出你可以扩展的代码的确切位置。不过,我试图解释你能做什么。通常在dataInit 内调用$(elem).autocomplete。 jQuery UI Autocomplete 支持select 回调(参见here 示例),您可以使用它在Autorizacion 列中设置新值。您使用name: 'ofc_autorizacion' 作为列。所以搜索工具栏输入栏的idgs_ofc_autorizacion,可以通过$("#gs_ofc_autorizacion").val("5031124051");访问。如果 jQuery UI 自动完成从服务器返回的数据是对象数组格式(例如具有属性valueautorizacion 的对象数组),那么您可以在ui.item 中找到相同的属性。它可以简化您的代码。我希望你明白我的意思。

    更新:我看到网格上方的行不是来自搜索工具栏,而是来自内联编辑。您使用 var id = $.jgrid.randId(); 作为第一行的 id。所以输入字段的 id 将是 id + "_ofc_autorizacion" 而不是 "gs_ofc_autorizacion"

    【讨论】:

    • 我已经用代码自动完成更新了我的问题,希望你能帮助我吗?
    • @raranibar:因为ofc_autorizacion 列具有editable: true 属性,所以可编辑行应该包含&lt;input name="ofc_autorizacion" id="123_ofc_autorizacion" type="text" .../&gt;(其中123 是rowid,您可以在select 自动完成回调中找到$(elem).closest("tr").attr("id") )。因此,您可以将您的 select 回调修改为大约以下 select: function (event, ui) { $(elem).val(ui.item.value); $(elem).closest("tr").find("input[name=ofc_autorizacion]").val(ui.item.id); $(elem).focus().trigger({ type: "keypress", charCode: 13 }); }
    猜你喜欢
    • 2023-01-20
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    相关资源
    最近更新 更多