Drag and drop between grids.
Try to drag a row from grid top to grid below.
Script uses a server side adding and dropping
<?php
require_once '../../../../php/demo/tabs.php';
?>
<!DOCTYPE html>
<html>
<head>
<title>jqGrid PHP Demo</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../../../css/jquery-ui.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../../../../css/trirand/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="../../../../css/ui.multiselect.css" />
<style type="text">
html, body {
margin: 0; /* Remove body margin/padding */
padding: 0;
overflow: hidden; /* Remove scroll bars on browser window */
font-size: 75%;
}
#tags {z-index: 900}
</style>
<script src="../../../../js/jquery.min.js" type="text/javascript"></script>
<script src="../../../../js/trirand/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../../../js/trirand/jquery.jqGrid.min.js" type="text/javascript"></script> <script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
$.jgrid.defaults.width = "700";
</script>
<script src="../../../../js/jquery-ui.min.js" type="text/javascript"></script>
</head>
<body>
<div>
<?php
include ("grid.php");
echo "<div style='width:600px;text-align:center;'>\/</div>";
include ("grid2.php");
?>
</div>
<br/>
<?php tabs(array("grid.php", "grid2.php","dragdrop.php"));?>
</body>
</html>
grid.php.
<?php
require_once '../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/PHPSuito/jqGrid.php";
// include the driver class
require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, ShipName, Freight FROM orders WHERE OrderID <= 500000';
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
// Set in grid options scroll to 1
$grid->setGridOptions(array("rowNum"=>100,"sortname"=>"OrderID","height"=>200));
// Change some property of the field(s)
$grid->setColProperty("OrderID", array("width"=>80));
$grid->setColProperty("OrderDate", array(
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y")
)
);
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
grid2.php.
<?php
require_once '../../jq-config.php';
// include the jqGrid Class
require_once ABSPATH."php/PHPSuito/jqGrid.php";
// include the driver class
require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid1 = new jqGridRender($conn);
// Write the SQL Query
$grid1->SelectCommand = 'SELECT OrderID, OrderDate, CustomerID, ShipName, Freight FROM orders WHERE OrderID>=50000';
// set the ouput format to json
$grid1->dataType = 'json';
// Let the grid create the model
$grid1->setColModel();
// Set the url from where we obtain the data
$grid1->setUrl('grid2.php');
// Set in grid options scroll to 1
$grid1->setGridOptions(array("rowNum"=>100,"sortname"=>"OrderID","height"=>200));
// Change some property of the field(s)
$grid1->setColProperty("OrderID", array("width"=>80));
$grid1->setColProperty("OrderDate", array(
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y")
)
);
$dragdrop = <<< DRAG
jQuery("#grid").jqGrid('gridDnD',{
connectWith:'#grid2',
beforedrop: function(ev, ui, row) {
jQuery.ajax({
url: 'dragdrop.php',
data : row,
async: false,
success : function( response )
{
alert(response);
// we can cancel drag and drop if we have to set
// ui.helper.dropped = false;
}
})
}
});
DRAG;
$grid1->setJSCode($dragdrop);
// Enjoy
$grid1->renderGrid('#grid2','#pager2',true, null, null, true,true);
dragdrop.php.
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*
*
*/
$rowid = $_GET['OrderID'];
echo "Row: ".$rowid." succefull droped from orders and added in table2";
// we can get all the data from the grid delete it from orders and insert it into the new table