Advertisement
gridphp

Untitled

May 30th, 2014
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.51 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. $g = new jqgrid();
  21.  
  22. $col = array();
  23. $col["title"] = "Id"; // caption of column
  24. $col["name"] = "id";
  25. $col["width"] = "10";
  26. $cols[] = $col;    
  27.  
  28. // temporary column for column placeholder comparison in formatting
  29. $col = array();
  30. $col["title"] = "jId"; // caption of column
  31. $col["name"] = "jid";
  32. $col["width"] = "10";
  33. $col["link"] = "http://www.google.es/q/{search}";
  34. $col["linkoptions"] = "target='_blank'";
  35. $cols[] = $col;    
  36.  
  37. $col = array();
  38. $col["title"] = "Client";
  39. $col["name"] = "name";
  40. $col["width"] = "100";
  41. $col["search"] = true;
  42. $col["editable"] = false;
  43. $col["export"] = false; // this column will not be exported
  44. $col["link"] = "http://localhost/?id={id}"; // e.g. http://domain.com?id={id} given that, there is a column with $col["name"] = "id" exist
  45. $col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
  46. $cols[] = $col;
  47.  
  48. $col = array();
  49. $col["title"] = "Date Calc";
  50. $col["name"] = "invdate_calc"; // sql aliased column of invdate with date format (20120101)
  51. $col["width"] = "20";
  52. $col["editable"] = false; // this column is editable
  53. $col["hidden"] = true; // this column is hidden, just used for formatting
  54. $col["search"] = false;
  55. $cols[] = $col;
  56.  
  57. $col = array();
  58. $col["title"] = "Date";
  59. $col["name"] = "invdate";
  60. $col["width"] = "20";
  61. $col["editable"] = true; // this column is editable
  62. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  63. $col["editrules"] = array("required"=>true); // and is required
  64. $col["formatter"] = "date"; // format as date
  65. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y');
  66. $col["search"] = false;
  67. $cols[] = $col;
  68.  
  69. $grid["sortname"] = 'id'; // by default sort grid by this field
  70. $grid["sortorder"] = "desc"; // ASC or DESC
  71. $grid["caption"] = "Invoice Data"; // caption of grid
  72. $grid["autowidth"] = true; // expand grid to screen width
  73. $grid["multiselect"] = false; // allow you to multi-select through checkboxes
  74. $grid["reloadedit"] = true;
  75.  
  76. $g->set_options($grid);
  77.  
  78. // conditional css formatting of rows
  79.  
  80. $f = array();
  81. $f["column"] = "name"; // exact column name, as defined above in set_columns or sql field name
  82. $f["op"] = "cn"; // cn - contains, eq - equals
  83. $f["value"] = "Ana";
  84. // $f["css"] = "'background-color':'red'";
  85. $f["class"] = "focus-row-2"; // css class name
  86. $f_conditions[] = $f;
  87.  
  88. $g->set_conditional_css($f_conditions);
  89.  
  90. $g->set_actions(array( 
  91.                         "add"=>false, // allow/disallow add
  92.                         "edit"=>true, // allow/disallow edit
  93.                         "delete"=>true, // allow/disallow delete
  94.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  95.                         "autofilter" => true, // show/hide autofilter for search
  96.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  97.                     )
  98.                 );
  99.  
  100. // you can provide custom SQL query to display data
  101. $g->select_command = "SELECT i.id, 10 as jid, invdate, date_format(invdate,'%Y%m%d') as invdate_calc, c.name FROM invheader i
  102.                         left JOIN clients c ON c.client_id = i.client_id";
  103.  
  104. // this db table will be used for add,edit,delete
  105. $g->table = "invheader";
  106.  
  107. // pass the cooked columns to grid
  108. $g->set_columns($cols);
  109.  
  110. // generate grid output, with unique grid name as 'list1'
  111. $out = $g->render("list1");
  112. ?>
  113. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  114. <html>
  115. <head>
  116.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>  
  117.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  118.    
  119.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  120.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  121.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  122.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  123. </head>
  124. <body>
  125.     <style>
  126.     tr.focus-row-2
  127.     {
  128.         background: Bisque;
  129.     }
  130.     </style>
  131.     <div style="margin:10px">
  132.     <br>
  133.     <?php echo $out?>
  134.     </div>
  135. </body>
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement