EasyUI Forum
December 16, 2025, 10:03:09 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED]Drag and drop between datagrids  (Read 106 times)
jega
Full Member
***
Posts: 232


View Profile
« on: December 13, 2025, 02:27:58 PM »

HI.

Have searched around but not found exact what i need.

Have a datagrid with players and 4 datagrids for teams.

Players dg have an ID, playerUUID and playerName column. Team dg has playerUUID and playerName columns

Want to drag from player to a team (and remove it from player). If placed wrong, drag it from team back to player. No dnd between teams.

Need it in a small project in 8 days. ;-)

Any help

Regards Jesper
« Last Edit: Today at 02:49:57 AM by jega » Logged
jarry
Administrator
Hero Member
*****
Posts: 2305


View Profile Email
« Reply #1 on: December 15, 2025, 11:50:07 PM »

Here is the example shows how to drag a row from player datagrid and drop it on the team datagrid.
Code:
<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>jQuery EasyUI Demo</title>
  <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
  <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
  <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
  <script type="text/javascript" src="https://www.jeasyui.com/easyui/datagrid-dnd.js"></script>
  <script>
    var data1 = [
      { "playerUUID": "UUID1", "playerName": "Name1" },
      { "playerUUID": "UUID2", "playerName": "Name2" },
      { "playerUUID": "UUID3", "playerName": "Name3" },
      { "playerUUID": "UUID4", "playerName": "Name4" },
      { "playerUUID": "UUID5", "playerName": "Name5" }
    ];
    var data2 = [
      { "playerUUID": "UUID6", "playerName": "Name6" },
      { "playerUUID": "UUID7", "playerName": "Name7" }
    ];
    $(function () {
      $('#dgPlayer').datagrid({
        singleSelect: true,
        data: data1,
        onLoadSuccess: function () {
          $(this).datagrid('enableDnd');
        },
        onBeforeDrop: function () {
          return false;
        }
      })
      $('#dgTeam').datagrid({
        singleSelect: true,
        data: data2,
        onLoadSuccess: function () {
          $(this).datagrid('enableDnd');
        },
        onBeforeDrag: function () {
          return false;
        }
      })

    })
  </script>
</head>

<body>
  <div class="f-row">
    <div>
      <table id="dgPlayer" title="Player" style="width:400px;height:250px">
        <thead>
          <tr>
            <th data-options="field:'playerUUID',width:100">playerUUID</th>
            <th data-options="field:'playerName',width:200">playerName</th>
          </tr>
        </thead>
      </table>
    </div>
    <div>
      <table id="dgTeam" title="Team" style="width:400px;height:250px">
        <thead>
          <tr>
            <th data-options="field:'playerUUID',width:100">playerUUID</th>
            <th data-options="field:'playerName',width:200">playerName</th>
          </tr>
        </thead>
      </table>
    </div>
  </div>


</body>

</html>
Logged
jega
Full Member
***
Posts: 232


View Profile
« Reply #2 on: Today at 02:35:59 AM »

Hi jarry

Thanks for an sample. That was more easy than i thought.

But, it can only drag from player to team, not from team to player.
Logged
jega
Full Member
***
Posts: 232


View Profile
« Reply #3 on: Today at 02:49:40 AM »

Found the answer.

It was the onBeforeDrag and -drop i need to handle.

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!