Author Topic: drag and drop bwtween two grids  (Read 2748 times)

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 7
    • View Profile
drag and drop bwtween two grids
« on: July 22, 2020, 02:23:13 pm »
dear sir,

I copied the code from the demo https://paramquery.com/pro/demos/dnd_grids. but when I drag a row data from one grid and drop it on the second grid. there is no data showing. my code is as follow. the result is as the pictures. can  you help me to find the reason?



var colM = [
            //first column to show grouping (for both pivot and row grouping mode). ( used along with groupModel.titleInFirstCol )
            //first column to show grouping. ( used along with groupModel.titleInFirstCol )




            {title: "删除数据", dataIndx:'del', editable: false, minWidth: 100, sortable: false,align:"center",copy: false,
                render: function (ui) {
                /*
                    if(( ui.rowIndx ==($('#selnumber').val()-1))){
                        return '';
                    }else{
                        return "<button type='button' class='delete_btn'><span style='color: red'>删除</span> </button>";
                    }
                */
                    return "<button type='button' class='delete_btn'><span style='color: red'>删除</span> </button>";

            },
            postRender: function (ui) {
                var grid1 = this,
                    $cell = grid1.getCell(ui);
                $cell.find(".delete_btn")
                    .button({ icons: { primary: 'ui-icon-scissors'} })
                    .bind("click", function (evt) {
                        grid1.deleteRow({ rowIndx: ui.rowIndx });
                    });
            }
        },
            {title: "院校代码", dataIndx: "UnivCode", editable: false, sortable: false,width: 80, },
            {title:'院校名称',width:160,dataIndx:'UnivName',editable: false,sortable: false, halign:'center',
                filter: {
                    crules: [{condition: 'range'}]
                }
            },

            {title: "专业代码", dataIndx: "MajorCode", dataType:'string', editable: false,sortable: false, width: 80,
                // format: function (val) {
                //     return " "+val;
                // }
            },
            {title: "专业名称", dataIndx: "MajorName", width: 300, editable: false,sortable: false,halign:'center',
                filter: {
                    crules: [{condition: 'range'}]
                }
            },
            {title:'招生类型',width:60,dataIndx:'UnivType', editable: false,align:'center',
                filter: {
                    crules: [{condition: 'range'}]
                }
            },

            {title: "科目要求", dataIndx: "SubjectName", width: 100, editable: false,sortable: false,align:'center'},
            {title: "学历层次", dataIndx: "Level", width: 60, editable: false,sortable: false,align:'center'},
            // {title: "招生批次", dataIndx: "Batch", width: 60, editable: false,sortable: false,align:'center'},
            {title: "加权位次", dataIndx: "WeightPos", width: 80, editable: false,sortable: false,align:'center'},
            {title: "招生计划数", dataIndx: "PlanNum", width: 60, editable: false,sortable: false,align:'center'},
            {title: "学制", dataIndx: "UnivYears", width: 60, editable: false,sortable: false,align:'center',},
            {title: "学费", dataIndx: "FeeYear", width: 60, editable: false,sortable: false,align:'center'},
            {title:'所在省',width:100,dataIndx:'UnivProv', editable: false,sortable: false,align:'center',
                filter: {
                    crules: [{condition: 'range'}]
                }
            },
            {title:'所在市',width:100,dataIndx:'UnivCity', editable: false,sortable: false,align:'center',
                filter: {
                    crules: [{condition: 'range'}]
                }
            },
            {title:'办学性质',width:60,dataIndx:'UnivProty', editable: false,sortable: false,align:'center',
                filter: {
                    crules: [{condition: 'range'}]
                }
            },
            //{title:'位次差',dataIndx:'ChaPos',width:100,  editable: false,sortable: false,align:'center', },


            // {title:'与{$lastyear}年分差',dataIndx:'ChaLN',dataType:'float',width:120, format:'###.##', editable: false,copy:false,align:'center',
            {title:'与{$lastyear}年分差',dataIndx:'ChaLN',width:80, dataType:'integer', editable: false,sortable: false,align:'center',

            },
            {title:'与{$bflastyear}年分差',dataIndx:'ChaQN',width:80, dataType:'integer',editable: false,sortable: false,align:'center',

            },
            {title:'与{$bfbflastyear}年分差',dataIndx:'ChaDQN',width:80, dataType:'integer', editable: false,sortable: false,align:'center',

            },
            {title: "序号", dataIndx: "ID", width: 10, align:'center',hidden:true,copy:false,},
            {title: "用户序号", dataIndx: "uid", width: 10, align:'center',hidden:true,copy:false,},

        ];
        userid=$('#userid').val();
        var url='../../ptgkgxzxzhongxuannewdata?id='+userid;
        var dataModel = {
            location: "remote",
            dataType: "JSON",
            method: "POST",
            //cache: false,
            recIndx: "ID",
            //url: '../../ptgkgxzxzhongxuannewdatanew',
            url: url,
            getData: function (data) {
                datalocal=data;
                return { data: data};
            }
        };


        $("#dndgrid1").pqGrid({
            height: 500,
            width: '45%',
            colModel: $.extend(true, [], colM),
            //dataModel: $.extend(true, {}, datalocal),
            dataModel: $.extend(true, {}, dataModel),
            //colModel: colM,
            //dataModel: { data: data,recIndx: "ID" },
            complete: function () {
                this.flex();
            },
            dragModel:{
                on: true,
                clsDnD: 'dnd1',
                diHelper:['UnivName'],
                //beforeDrop: function(){

                //}
            },
            dropModel:{
                on: true,
                accept: '.dnd2'
            },
            //pageModel: { type: 'local', rPP: 20, rPPOptions: [1, 10, 20, 30, 40, 50, 100] },
            title: "原始表",
        });

        $("#dndgrid2").pqGrid({
            height: 500,
            width: '45%',
            colModel: $.extend(true, [], colM),
            dataModel: $.extend(true, {}, dataModel),
            //dataModel: $.extend(true, {}, datalocal),
            complete: function () {
                this.flex();
            },
            dragModel:{
                on: true,
                clsDnD: 'dnd2',
                //diHelper:['OrderID']
            },
            dropModel:{
                on: true,
                accept: '.dnd1,.dnd2',

            },

        });

    });
« Last Edit: July 22, 2020, 09:46:40 pm by paramvir »

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: drag and drop bwtween two grids
« Reply #1 on: July 22, 2020, 08:10:09 pm »
sorry for the wrong pictures. see the attached new.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: drag and drop bwtween two grids
« Reply #2 on: July 22, 2020, 10:07:06 pm »
It seems recIndx: "ID" in the dataModel is causing the issue.

When you drag and drop a row from 1st to 2nd grid having same data, it causes a duplicate ID in 2nd grid with primary key violation.
« Last Edit: July 23, 2020, 07:32:46 am by paramvir »

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: drag and drop bwtween two grids
« Reply #3 on: July 23, 2020, 02:04:28 pm »
dear Paramvir,

  1. I comment out the recIndx: 'ID' for the dataModel, but the problem is still there.
  2. I delete the grid 2 content after loading, then drop the data from the grid 1, the data is still showing blank.

is there any other reason?

for my plan, I wan to show all the data in grid 1, then drag them one by one to grid 2 and arrange the order of them. for one grid drag and drop is ok, but with two grids, it looks clear for the customer. can you give me some suggsetion for it?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: drag and drop bwtween two grids
« Reply #4 on: July 23, 2020, 07:45:28 pm »
Could you please share a live example of the issue in jsfiddle or stackblitz.

[email protected]

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: drag and drop bwtween two grids
« Reply #5 on: July 24, 2020, 10:01:16 am »
dear Paramvir,

solved the problem. when I set the editable with true, the data can be shown.
because I don't want the customer to edit the data, I need the editable with false, then how to deal with the problem?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: drag and drop bwtween two grids
« Reply #6 on: July 24, 2020, 10:52:22 am »
beforeValidate event can be used to skip editable check.

Code: [Select]
beforeValidate: function(evt, ui){
if(ui.source == 'addNodes'){
ui.checkEditable = false;
}
},


As a side note:

You can save yourself the trouble of adding editable: false to each column by using global editable option.

https://paramquery.com/pro/api#option-editable