Advertisement
Guest User

Tagit code sample

a guest
Nov 4th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 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. $col = array();
  29. $col["title"] = "Client";
  30. $col["name"] = "client_id";
  31. $col["dbname"] = "invheader.client_id"; // this is required as we need to search in name field, not id
  32. $col["width"] = "100";
  33. $col["align"] = "left";
  34. $col["search"] = true;
  35. $col["editable"] = true;
  36. $col["edittype"] = "select"; // render as select
  37. # fetch data from database, with alias k for key, v for value
  38. $str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
  39. $col["editoptions"] = array("value"=>":;".$str);
  40. $col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ $('select[name=client_id]').select2({width:'80%', dropdownCssClass: 'ui-widget ui-jqdialog'}); },200); }";
  41. $cols[] = $col;
  42.  
  43. $col = array();
  44. $col["title"] = "Date";
  45. $col["name"] = "invdate";
  46. $col["width"] = "50";
  47. $col["editable"] = true; // this column is editable
  48. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  49. $col["editrules"] = array("required"=>true); // and is required
  50. $col["formatter"] = "date"; // format as date
  51. $col["search"] = false;
  52. $cols[] = $col;
  53.  
  54. $col = array();
  55. $col["title"] = "Amount";
  56. $col["name"] = "amount";
  57. $col["width"] = "50";
  58. $col["editable"] = true; // this column is editable
  59. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  60. $cols[] = $col;
  61.  
  62. $col = array();
  63. $col["title"] = "Note";
  64. $col["name"] = "note";
  65. $col["width"] = "50";
  66. $col["editable"] = true; // this column is editable
  67. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  68. $col["editoptions"]["dataInit"] = 'function(el){ setTimeout(function(){
  69. // remove nbsp from start
  70. if (jQuery(".FormGrid:visible").length) $(el)[0].parentNode.firstChild.remove();
  71.  
  72. $("input[name=note]").tagit({
  73. availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"]
  74. }); },200); }';
  75. $cols[] = $col;
  76.  
  77. $grid["sortname"] = 'id'; // by default sort grid by this field
  78. $grid["sortorder"] = "desc"; // ASC or DESC
  79. $grid["caption"] = "Invoice Data"; // caption of grid
  80. #$grid["autowidth"] = true; // expand grid to screen width
  81.  
  82. $g->set_options($grid);
  83.  
  84. $g->set_actions(array(
  85. "add"=>false, // allow/disallow add
  86. "edit"=>true, // allow/disallow edit
  87. "delete"=>true, // allow/disallow delete
  88. "export_pdf"=>true, // show/hide row wise edit/del/save option
  89. "rowactions"=>true, // show/hide row wise edit/del/save option
  90. "autofilter" => true, // show/hide autofilter for search
  91. )
  92. );
  93.  
  94. // to make dropdown work with export, we need clients.name as client_id logic in sql
  95. $g->select_command = "SELECT id, invdate, clients.name as client_id, amount, note FROM invheader
  96. INNER JOIN clients on clients.client_id = invheader.client_id
  97. ";
  98.  
  99. // this db table will be used for add,edit,delete
  100. $g->table = "invheader";
  101.  
  102. // pass the cooked columns to grid
  103. $g->set_columns($cols);
  104.  
  105. // generate grid output, with unique grid name as 'list1'
  106. $out = $g->render("list1");
  107. ?>
  108. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  109. <html>
  110. <head>
  111. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  112. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  113.  
  114. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  115. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  116. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  117. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  118.  
  119. <link href="//cdnjs.cloudflare.com/ajax/libs/select2/3.4.6/select2.css" rel="stylesheet"></link>
  120. <script src="//cdnjs.cloudflare.com/ajax/libs/select2/3.4.6/select2.min.js"></script>
  121.  
  122. <link href="//cdn.jsdelivr.net/tag-it/2.0/css/jquery.tagit.css" rel="stylesheet"></link>
  123. <script src="//cdn.jsdelivr.net/tag-it/2.0/js/tag-it.min.js"></script>
  124.  
  125. </head>
  126. <body>
  127. <style>
  128. .FormGrid ul.tagit {
  129. margin-left: 3px;
  130. margin-top: 0;
  131. }
  132. </style>
  133. <div style="margin:10px">
  134. <?php echo $out?>
  135. </div>
  136. </body>
  137. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement