Guest User

Untitled

a guest
May 7th, 2012
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3.     <head>
  4.  
  5.         <title>jqGrid</title>
  6.         <meta charset="UTF-8">
  7.  
  8.         <link rel="stylesheet" type="text/css" href="jqueryui/development-bundle/themes/redmond/jquery-ui-1.8.20.custom.css" />
  9.         <link rel="stylesheet" type="text/css" href="jqGridPHP_Sources_4_3_2_0/themes/ui.jqgrid.css" />
  10.         <link rel="stylesheet" type="text/css" media="screen" href="jqGridPHP_Sources_4_3_2_0/themes/ui.multiselect.css" />
  11.  
  12.         <style type="text/css">
  13.  
  14.         </style>
  15.  
  16.         <script src="js/jquery-1.7.2.js" type="text/javascript"></script>
  17.         <script src="jqGridPHP_Sources_4_3_2_0/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  18.         <script src="jqGridPHP_Sources_4_3_2_0/js/src-grid/jquery.jqGrid.js" type="text/javascript"></script>
  19.         <script src="jqueryui/js/jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>  
  20.         <script src="jqueryui/development-bundle/ui/jquery.ui.core.js" type="text/javascript"></script>
  21.         <script src="jqueryui/development-bundle/ui/jquery.ui.datepicker.js" type="text/javascript"></script>  
  22.  
  23.         <script>
  24.             $.jgrid.no_legacy_api = true;
  25.             $.jgrid.useJSON = true;
  26.        
  27.             $(document).ready(function() {
  28.                 <?php include "grid1.php"; ?>
  29.                
  30.              });       
  31.                
  32.         </script>
  33.  
  34.     </head>
  35.  
  36.     <body>
  37.  
  38.         <table id="grid"></table>
  39.         <div id="pager"></div>
  40.  
  41.     </body>
  42. </html>
  43.  
  44.  
  45. ///////grid1.php//////
  46.  
  47. <?php
  48.  
  49. // include database configuration credentials
  50. require_once 'jqGridPHP_Sources_4_3_2_0/jq-config.php';
  51. // include the jqGrid Class
  52. require_once "jqGridPHP_Sources_4_3_2_0/php/jqGrid.php";
  53. // include the PDO driver class
  54. require_once "jqGridPHP_Sources_4_3_2_0/php/jqGridPdo.php";
  55. // Connection to the server
  56. $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
  57. // instruct the database that we use utf-8 encoding
  58. $conn->query("SET NAMES utf8");
  59. // Create the jqGrid instance
  60. $grid = new jqGridRender($conn);
  61. // Write the SQL Query
  62. $grid->SelectCommand = 'SELECT OrderID, CustomerID, EmployeeID, OrderDate  FROM orders';
  63.  
  64. // set the ouput format to json
  65. $grid->dataType = 'json';
  66.  
  67. // Definition of the labels
  68. $mylabels = array("OrderID"=>"Order ID", "CustomerID"=>"Customer ID", "EmployeeID"=>"Employee ID", "OrderDate"=>"OrderDate");
  69. // Let the grid create the model with the desired labels
  70. $grid->setColModel(null, null, $mylabels);
  71. // Change some property of the field(s)
  72. $grid->setColProperty("OrderDate", array("width"=>100));
  73.  
  74.  
  75. // Set the url from where we obtain the data
  76. // make sure this path is the same as your include in your main page
  77. $grid->setUrl('grid1.php');
  78.  
  79. // Set grid caption using the option caption
  80. $grid->setGridOptions(array(
  81.     "caption"=>"Northwinds Orders",
  82.     "rowNum"=>1000,
  83.     "sortname"=>"EmployeeID",
  84.     "rowList"=>array(10,20,1000)
  85.     ));
  86.  
  87. $grid->setGridOptions(array("width"=>1000));
  88. $grid->setGridOptions(array("height"=>350));
  89.  
  90.  
  91.  
  92.  
  93. // javascriptCode for the datepicker
  94. $mydatepicker = <<<DATEPICK
  95. function(el)
  96. {
  97.    setTimeout(function(){
  98.       jQuery(el).datepicker({dateFormat:'dd/mm/yy'});
  99.    },200);
  100. }
  101. DATEPICK;
  102.  
  103. // Set the column property
  104. $grid->setColProperty('OrderDate', array(
  105.    "formatter"=>'date',
  106.    "editoptions"=>array("dataInit"=>"js:".$mydatepicker),
  107.    "searchoptions"=>array("dataInit"=>"js:".$mydatepicker)
  108. ));
  109.  
  110. // add navigator with the default properties
  111. $grid->navigator = true;
  112.  
  113.  
  114.  
  115. /*
  116. $onselect = <<<ONSELECTROW
  117. function(rowid, selected)
  118. {
  119.    alert(rowid);
  120. }
  121. ONSELECTROW;
  122.  
  123. $grid->setGridEvent('onSelectRow',$onselect);
  124. */
  125.  
  126.  
  127.  
  128.  
  129. // Run the script
  130. $grid->renderGrid('#grid','#pager',false, null, null, false, false, true);
  131. //renderGrid( $tblelement, $pager , $script , $summary, $params , $createtbl , $createpg , $echo );
  132.  
  133. // clear database connection
  134. $conn = null;
  135.  
  136.  
  137. ?>
Advertisement
Add Comment
Please, Sign In to add comment