Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / PHP

Drag & Drop Rows Between Grids

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
30 Mar 2017CPOL 11.1K   3   1
How to drag and drop rows between grids

dnd-phpgrid

You can drag and drop rows between two or more grids using a mouse.

In the demo, we have both orders and employees datagrids on the same page.

PHP
$dg = new C_DataGrid("select * from employees", "employeeNumber", "employees");
$dg->enable_edit("FORM", "CRUD");
$dg->display();

We add the following JavaScript to enable drag and drop between the two grids.

The Ondrop event posts the row data to another URL “save_dropped_row.php”. You must implement this server side script to handle how you would like the row data to be saved.

JavaScript
<script>
$(function(){
  jQuery("#orders").jqGrid("sortableRows", {});
  jQuery("#employees").jqGrid("sortableRows", {});

  jQuery("#orders").jqGrid('gridDnD',{
    connectWith:'#employees',
    drop_opts:{
      hoverClass: "ui-state-active",
    },
    ondrop: function(evt, obj, data){
      $.ajax({
          method: "POST",
          url: "save_dropped_row.php",
          data: data,
        }).done(function( msg ) {
            console.log( "Data Saved: " + msg );
        })
    },
  });  
})
</script>

The complete drag and drog API documentation can be found on jQuery UI draggable and droppable widgets.

Run live demo!

The post Drag & Drop Rows Between Grids appeared first on phpGrid.

This article was originally posted at http://phpgrid.com/example/drag-drop-rows-grids

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
He likes programming and iPod.

Comments and Discussions

 
QuestionNeed full source code Pin
Tridip Bhattacharjee30-Mar-17 22:25
professionalTridip Bhattacharjee30-Mar-17 22:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.