Advertisement
gridphp

subgrid toggle

Jun 6th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 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.5.2
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. // include db config
  11. include_once("../../config.php");
  12.  
  13. // set up DB
  14. mysql_connect(PHPGRID_DBHOST, PHPGRID_DBUSER, PHPGRID_DBPASS);
  15. mysql_select_db(PHPGRID_DBNAME);
  16.  
  17. // include and create object
  18. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  19.  
  20. $grid = new jqgrid();
  21.  
  22. $opt["caption"] = "Clients Data";
  23. $opt["height"] = "";
  24. $opt["rowNum"] = "5";
  25.  
  26. // following params will enable subgrid -- by default 'rowid' (PK) of parent is passed
  27. $opt["subGrid"] = true;
  28. $opt["subgridurl"] = "subgrid_detail.php";
  29.  
  30. //call some JS on subgrid load
  31. //$opt["subGridRowExpanded"] = "function(){ setTimeout(function(){ alert('connect ckeditor code'); },200);  }";
  32.  
  33. $opt["subgridparams"] = "client_id";
  34. // $opt["subgridparams"] = "name,gender,company"; // comma sep. fields. will be POSTED from parent grid to subgrid, can be fetching using $_POST in subgrid
  35. $grid->set_options($opt);
  36.  
  37. $grid->table = "clients";
  38. $out = $grid->render("list1");
  39. ?>
  40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  41. <html>
  42. <head>
  43.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/start/jquery-ui.custom.css"></link>
  44.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  45.    
  46.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  47.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  48.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  49.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  50. </head>
  51. <body>
  52.     <div style="margin:10px">
  53.     Subgrid example ... this file will load subgrid defined in 'subgrid_detail.php'
  54.     <br>
  55.     <br>
  56.     <?php echo $out?>
  57.     </div>
  58.     <script type="text/javascript">
  59.     jQuery(document).ready(function(){
  60.  
  61.         jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
  62.         {
  63.             'caption'      : 'Toggle Expand',
  64.             'buttonicon'   : 'ui-icon-plus',
  65.             'onClickButton': function()
  66.             {
  67.                
  68.                 var rowIds = jQuery("#list1").getDataIDs();
  69.                
  70.                 if ( ! jQuery(document).data('expandall') )
  71.                 {
  72.                     jQuery.each(rowIds, function (index, rowId) { jQuery("#list1").expandSubGridRow(rowId); });
  73.                     jQuery(document).data('expandall',1);
  74.                 }
  75.                 else
  76.                 {
  77.                     jQuery.each(rowIds, function (index, rowId) { jQuery("#list1").collapseSubGridRow(rowId); });
  78.                     jQuery(document).data('expandall',0);
  79.                 }
  80.                
  81.             },
  82.             'position': 'last'
  83.         });
  84.     });
  85.     </script>  
  86. </body>
  87. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement