Author Topic: Multiple rows drag and drop  (Read 2990 times)

Jignesh

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 46
    • View Profile
Multiple rows drag and drop
« on: July 03, 2020, 02:16:47 pm »
Hi Paramvir,

How we will drag and drop multiple rows at a single time.

Can you please give me demo example for below URL:
https://paramquery.com/pro/demos/dnd_grid

I want 1 to 5 and 6,10 rows to drag and drop.

Thank you

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: Multiple rows drag and drop
« Reply #1 on: July 03, 2020, 06:26:26 pm »
First we add a checkbox column to check multiple rows.

Code: [Select]
{
dataIndx: "state",
maxWidth: 30,
minWidth: 30,
align: "center",
resizable: false,
title: "",
menuIcon: false,
type: 'checkbox',
sortable: false,
editor: false,
dataType: 'bool'
},

Then implement dragModel.dragNodes to return checked rows.

Code: [Select]
            dragModel:{
                on: true,
                diHelper:['OrderID'],
dragNodes: function(rd, evt){               
                    return this.Checkbox('state').getCheckedNodes();
                }
            },

Jignesh

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 46
    • View Profile
Re: Multiple rows drag and drop
« Reply #2 on: July 17, 2020, 05:52:10 pm »
Hi Paramvir,

This code only work for multiple row drga nad drop but if user want to single row drag and drop without select checkbox then how we will reach this functionality.

Below steps:
1) Select multiple rows then drag and drop. It's work perfectly.
Query ) After drop I want to remove selected checkbox.

2) If user want to drag and drop single row so currently I am selecting single row then drag and drop.
Query ) How to drag and drop single row without select checkbox.



Thank you,
Jignesh

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: Multiple rows drag and drop
« Reply #3 on: July 20, 2020, 09:17:38 am »
1. Use moveNode event to clear checkboxes.
Code: [Select]
moveNode: function(){
this.Checkbox('state').unCheckAll();
},

2. Update dragModel.dragNodes

Code: [Select]
            dragModel:{
                on: true,
                diHelper:['OrderID'],
dragNodes: function(rd, evt){               
                    var checkNodes = this.Checkbox('state').getCheckedNodes();
    return (checkNodes.length && checkNodes.indexOf(rd)>-1 )? checkNodes: [ rd ];
                }
            },

mikep

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 132
    • View Profile
Re: Multiple rows drag and drop
« Reply #4 on: September 15, 2020, 02:23:42 am »
I'm already using a checkbox in my grid. Is there another alternative for multi-select for the drag/drop? Can I shift/click to select multiple rows?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6125
    • View Profile
Re: Multiple rows drag and drop
« Reply #5 on: September 15, 2020, 05:17:45 pm »
yes row selections can also be used instead of checkboxes for multi rows drag n drop by doing these 2 changes in selectionModel and dragModel.dragNodes

Code: [Select]
selectionModel: {type:'row'},

Code: [Select]
dragModel:{
        on: true,
        diHelper:['OrderID'],
dragNodes: function(rd, evt){
var arr = this.SelectRow().getSelection().map(function(obj){
return obj.rowData;
});
return (arr.length && arr.indexOf(rd) > -1 )? arr: [ rd ];
}
},
« Last Edit: September 15, 2020, 05:19:56 pm by paramvir »