Advertisement
gridphp

Custom Edit form

Feb 25th, 2014
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.30 KB | None | 0 0
  1. <?php
  2. /**
  3.  * PHP Grid Component
  4.  *
  5.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  6.  * @version 1.4.8
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. $conn = mysql_connect("localhost", "root", "");
  11. mysql_select_db("griddemo");
  12.  
  13. $base_path = strstr(realpath("."),"demos",true)."lib/";
  14. include($base_path."inc/jqgrid_dist.php");
  15.  
  16. // you can customize your own columns ...
  17.  
  18. $col = array();
  19. $col["title"] = "Id"; // caption of column
  20. $col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  21. $col["width"] = "10";
  22. $cols[] = $col;    
  23.  
  24. $col = array();
  25. $col["title"] = "Client";
  26. $col["name"] = "name";
  27. $col["width"] = "100";
  28. $col["editable"] = false; // this column is not editable
  29. $col["search"] = false; // this column is not searchable
  30.  
  31. $cols[] = $col;
  32.  
  33. $col = array();
  34. $col["title"] = "Date";
  35. $col["name"] = "invdate";
  36. $col["width"] = "50";
  37. $col["editable"] = true; // this column is editable
  38. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  39. $col["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
  40. $col["formatter"] = "date"; // format as date
  41. $cols[] = $col;
  42.        
  43. $col = array();
  44. $col["title"] = "Total";
  45. $col["name"] = "total";
  46. $col["width"] = "50";
  47. $col["editable"] = true;
  48. // default render is textbox
  49. $col["editoptions"] = array("value"=>'10');
  50.  
  51. $cols[] = $col;
  52.  
  53. $col = array();
  54. $col["title"] = "Closed";
  55. $col["name"] = "closed";
  56. $col["width"] = "50";
  57. $col["editable"] = true;
  58. $col["edittype"] = "checkbox"; // render as checkbox
  59. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  60. $cols[] = $col;
  61.  
  62. # Custom made column to show link, must have default value as it's not db driven
  63. $col = array();
  64. $col["title"] = "Logo";
  65. $col["name"] = "logo";
  66. $col["width"] = "40";
  67. $col["align"] = "center";
  68. $col["search"] = false;
  69. $col["sortable"] = false;
  70. # class='fancybox' to open image in fancybox
  71. $col["default"] = "<a class='fancybox' href='http://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png'><img height=25 src='http://ssl.gstatic.com/ui/v1/icons/mail/logo_default.png'></a>";
  72. $cols[] = $col;
  73.  
  74. # Custom made column to show link, must have default value as it's not db driven
  75. $col = array();
  76. $col["title"] = "Details";
  77. $col["name"] = "more_options";
  78. $col["width"] = "30";
  79. $col["align"] = "center";
  80. $col["search"] = false;
  81. $col["sortable"] = false;
  82. $buttons_html = "<a target='_blank' class='fancybox' data-fancybox-type='iframe' href='http://jqgrid/dev/demos/editing/index.php' style='text-decoration:none; white-space:none; border:1px solid gray; padding:2px; position:relative; width:25px; color:red'>Buy</a> <a target='_blank' href='http://www.google.com?id={id}' style='text-decoration:none; white-space:none; border:1px solid gray; padding:2px; position:relative; width:25px; color:green'>Try</a>";
  83. $col["default"] = $buttons_html;
  84. $cols[] = $col;
  85.  
  86. # Customization of Action column width and other properties
  87. $col = array();
  88. $col["title"] = "Action";
  89. $col["name"] = "act";
  90. $col["width"] = "50";
  91. $cols[] = $col;
  92.  
  93. $g = new jqgrid();
  94.  
  95. $grid["rowNum"] = 10; // by default 20
  96. $grid["sortname"] = 'id'; // by default sort grid by this field
  97. $grid["sortorder"] = "desc"; // ASC or DESC
  98. $grid["caption"] = "Invoice Data"; // caption of grid
  99. $grid["autowidth"] = true; // expand grid to screen width
  100.  
  101. $g->set_options($grid);
  102.  
  103. $g->set_actions(array( 
  104.                         "add"=>true, // allow/disallow add
  105.                         "edit"=>false, // allow/disallow edit
  106.                         "delete"=>true, // allow/disallow delete
  107.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  108.                         "export"=>true, // show/hide export to excel option
  109.                         "autofilter" => true, // show/hide autofilter for search
  110.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  111.                     )
  112.                 );
  113.  
  114. // you can provide custom SQL query to display data
  115. $g->select_command = "SELECT * FROM (SELECT i.id, invdate , c.name,
  116.                         i.note, i.total, i.closed FROM invheader i
  117.                         INNER JOIN clients c ON c.client_id = i.client_id) o";
  118.  
  119. // this db table will be used for add,edit,delete
  120. $g->table = "invheader";
  121.  
  122. // pass the cooked columns to grid
  123. $g->set_columns($cols);
  124.  
  125. // generate grid output, with unique grid name as 'list1'
  126. $out = $g->render("list1");
  127. ?>
  128. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  129. <html>
  130. <head>
  131.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>  
  132.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  133.    
  134.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  135.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  136.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  137.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  138.  
  139.     <!-- Add fancyBox main JS and CSS files -->
  140.     <link type="text/css" rel="stylesheet" href="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.css" />
  141.     <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.js"></script>
  142.  
  143. </head>
  144. <body>
  145.  
  146.    
  147.     <script>
  148.     // on dbl click event on list
  149.     var opts = {
  150.         'ondblClickRow': function (id) {
  151.             window.open("edit.php?id="+id)
  152.         }
  153.     };
  154.  
  155.     </script>
  156.  
  157.     <div style="margin:10px">
  158.     <?php echo $out?>
  159.     </div>
  160.  
  161.     <script>
  162.  
  163.     // custom edit button on grid
  164.     jQuery(document).ready(function(){
  165.  
  166.         jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
  167.         {
  168.             'caption'      : 'Edit',
  169.             'buttonicon'   : 'ui-icon-pencil',
  170.             'onClickButton': function()
  171.             {
  172.                 // for selected rows
  173.                 var selectedRow = jQuery('#list1').jqGrid('getGridParam','selrow');
  174.  
  175.                 if (selectedRow.length == 0)
  176.                 {
  177.                     return;
  178.                 }
  179.  
  180.  
  181.                 var name = jQuery('#list1').jqGrid('getCell', selectedRow, 'name');
  182.                 var date = jQuery('#list1').jqGrid('getCell', selectedRow, 'invdate');
  183.                
  184.                 window.open("edit.php?id="+selectedRow+"&name="+name+"&date="+date);
  185.             },
  186.             'position': 'last'
  187.         });
  188.     });
  189.  
  190.     </script>
  191. </body>
  192. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement