jqgrid在表之间拖放

时间:2019-11-25 10:45:16

标签: jquery ajax drag-and-drop jqgrid subgrid

我用例程编写了一个小脚本。该脚本允许从表中拖动项目并从ajax调用中收集数据。

以下是脚本模式形式:

    $("#richspesa-gridrichdisp").jqGrid({
                url         :   'richspesa/richspesa_richdisp.php?anno=<?php echo date("Y"); ?>',
                datatype    :   'json',
                mtype       :   'GET',
                colNames    :   
                    [
                    'Numero',
                    'Denominazione',
                    'U.M.',
                    'Q.tà',
                    'Prezzo Unitario'
                    ],
                colModel    :   
                    [
                    {name:'rich_numero'      , index:'rich_numero'            , width:10                  },
                    {name:'rich_denomin'     , index:'Denominazione'          , width:55                  }, 
                    {name:'rich_um'          , index:'UM'                     , width:80  , align:'right' }, 
                    {name:'rich_qta'         , index:'QuantitaRichiesta'      , width:80  , align:'right' }, 
                    {name:'rich_prezzo'      , index:'Prezzo'                 , width:80  , align:'right' }
                    ],
                rowNum              :   -1,
                autowidth           :   true,
                height              :   600,
                loadtext            :   'Caricamento dati in corso...',
                sortname            :   'NumeroRichiesta',
                sortorder           :   'asc',
                gridview            :   true,
                pager               :   'richspesa-gridrichdisp-pager',
                pgbuttons           :   false,
                viewrecords         :   false,
                pgtext              :   null
            });
 set_draganddrop_richspesa_allegato('#richspesa-gridallegato');

第一次调用时,例程将放置目的地的调用设置为将目的地表的id作为参数传递给最后一行中的例程:

function set_draganddrop_richspesa_allegato(grid)
{
jQuery("#richspesa-gridrichdisp").jqGrid('gridDnD',
    {
    connectWith: grid,
    ondrop: function (evt, obj, data)                     
        {
        var richspesa_nr = $('#richspesa-modalform').attr('title');
        },
    onstop: function(event, ui, data)
        {
        }
    });
}

在另一个函数中,我设置了目标表,该目标表的每一行都有子网格:

    $("#richspesa-gridallegato").jqGrid({
                url         :   'richspesa/richspesa_allegato.php?anno=<?php echo date("Y"); ?>',
                datatype    :   'json',
                mtype       :   'GET',
                colNames    :   
                    [
                    'N° Rich.',
                    'Denominazione',
                    'U.M.',
                    'Q.tà',
                    'Prezzo Unitario',
                    'Azioni'
                    ],
                colModel    :   
                    [
                    {name:'richnumber'          , index:'richnumber'        , width:30                  },
                    {name:'richdescr'           , index:'richdescr'         , width:80                  }, 
                    {name:'richum'              , index:'richum'            , width:20  , align:'right' }, 
                    {name:'richqta'             , index:'richqta'           , width:20  , align:'right' }, 
                    {name:'richimporto'         , index:'richimporto'       , width:20  , align:'right' },
                    {name: 'Actions'            , index:'Actions'           , width:100 , height: 120, editable: true, formatter: 'actions',
                        formatoptions: {
                        keys: true,
                        editformbutton: true
                        }
                        }
                    ],
                rowNum              :   -1,
                autowidth           :   true,
                height              :   600,
                loadtext            :   'Caricamento dati in corso...',
                sortname            :   'richnumber',
                sortorder           :   'asc',
                gridview            :   true,
                pager               :   'richspesa-gridallegato-pager',
                pgbuttons           :   false,
                viewrecords         :   false,
                pgtext              :   null,
                subGrid             :   true,
                subGridOptions: { 
                    "plusicon" : "ui-icon-triangle-1-e",
                    "minusicon" :"ui-icon-triangle-1-s",
                    "openicon" : "ui-icon-arrowreturn-1-e",
                    "reloadOnExpand" : true,
                    "selectOnExpand" : true 
                    },
                subGridBeforeExpand: function(divid, rowid) 
                    {
                    var expanded = jQuery("td.sgexpanded", "#richspesa-gridallegato")[0];
                    if(expanded) {
                        setTimeout(function(){
                        $(expanded).trigger("click");
                        }, 100);
                        console.log("TEST ME "+expanded);
                        }
                    },
                subGridRowExpanded: function(subgrid_id, row_id) 
                    {
                    var ret = jQuery("#richspesa-gridallegato").jqGrid('getRowData',row_id);
                    var subgrid_table_id;
                    var richspesa_nr = $('#richspesa-modalform').attr('title');
                    subgrid_table_id = subgrid_id+"_t";
                    $("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
                    jQuery("#"+subgrid_table_id).jqGrid({
                        url         :   'richspesa/richspesa_suballegato.php',
                        postData    : { richnumero: richspesa_nr,
                                        rich_group: ret.rich_raggrupp},          
                        datatype    :   "json", 
                        colNames    : 
                            [
                            'N° Rich.',
                            'Descrizione',
                            'U.M.',
                            'Q.tà', 
                            'Prezzo Unit. (€)'
                            ], 
                        colModel    : 
                            [
                            {name:'richnumber',                 index:'richnumber',         width:90},
                            {name:'richdescr',                  index:'richdescr',          width:90},
                            {name:'richum',                     index:'richum',             width:90},
                            {name:'richqta',                    index:'richqta',            width:100},
                            {name:'richimporto',                index:'richimporto',        width:150,  editable:true}
                        ],  
                        rowNum      :   20, 
                        sortname    :   'richnumber', 
                        sortorder   :   "asc", 
                        height      :   '100%',
                        autowidth   :   true
                        });
                    set_draganddrop_richspesa_allegato('#'+subgrid_table_id);
                    },

                subGridRowColapsed: function(subgrid_id, row_id) 
                    {
                    set_draganddrop_richspesa_allegato('#richspesa-gridallegato');
                    }

            });

上面的代码应允许我在主表中拖动一个新项,然后在数据库中生成新记录,并在两种情况下修改该记录: 1.如果扩展记录关闭其他扩展记录,并允许在相应的子网格中放置新项目, 2.如果折叠,则将拖放属性返回主表。

麻烦的是,当我在主表中放置项目时:

  1. 主表将丢失数据的第一个字段(rich_numero)
  2. 表将被第二个字段数据替换(包含rich_denomin)

当我以常规行为将某个项目放入子网格中时,不会发生数据库不匹配的情况。怎么了 预先感谢

0 个答案:

没有答案