Advertisement
Guest User

mask-edit demo

a guest
Jan 12th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 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. $str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
  37. $col["editoptions"] = array("value"=>":;".$str);
  38. $col["edittype"] = "select"; // render as select
  39. $cols[] = $col;
  40.  
  41. $col = array();
  42. $col["title"] = "Date";
  43. $col["name"] = "invdate";
  44. $col["width"] = "50";
  45. $col["editable"] = true; // this column is editable
  46. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  47. $col["editrules"] = array("required"=>true); // and is required
  48. $col["formatter"] = "date"; // format as date
  49. $col["search"] = false;
  50. $cols[] = $col;
  51.  
  52. $col = array();
  53. $col["title"] = "Amount";
  54. $col["name"] = "amount";
  55. $col["width"] = "50";
  56. $col["editable"] = true; // this column is editable
  57. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  58. $cols[] = $col;
  59.  
  60. $col = array();
  61. $col["title"] = "Note";
  62. $col["name"] = "note";
  63. $col["width"] = "50";
  64. $col["editable"] = true; // this column is editable
  65. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  66. $cols[] = $col;
  67.  
  68. $grid["sortname"] = 'id'; // by default sort grid by this field
  69. $grid["sortorder"] = "desc"; // ASC or DESC
  70. $grid["caption"] = "Invoice Data"; // caption of grid
  71. #$grid["autowidth"] = true; // expand grid to screen width
  72.  
  73. $grid["add_options"]["afterShowForm"] = 'function(formid) { jQuery("#amount").mask("000.00"); }';
  74. $grid["edit_options"]["afterShowForm"] = 'function(formid) { jQuery("#amount").mask("000.00"); }';
  75.  
  76. $g->set_options($grid);
  77.  
  78. $g->set_actions(array(
  79. "add"=>false, // allow/disallow add
  80. "edit"=>true, // allow/disallow edit
  81. "delete"=>true, // allow/disallow delete
  82. "export_pdf"=>true, // show/hide row wise edit/del/save option
  83. "rowactions"=>true, // show/hide row wise edit/del/save option
  84. "autofilter" => true, // show/hide autofilter for search
  85. )
  86. );
  87.  
  88. // to make dropdown work with export, we need clients.name as client_id logic in sql
  89. $g->select_command = "SELECT id, invdate, clients.name as client_id, amount, note FROM invheader
  90. INNER JOIN clients on clients.client_id = invheader.client_id
  91. ";
  92.  
  93. // this db table will be used for add,edit,delete
  94. $g->table = "invheader";
  95.  
  96. // pass the cooked columns to grid
  97. $g->set_columns($cols);
  98.  
  99. // generate grid output, with unique grid name as 'list1'
  100. $out = $g->render("list1");
  101. ?>
  102. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  103. <html>
  104. <head>
  105. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  106. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  107.  
  108. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  109. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  110. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  111. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  112.  
  113. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery.mask/0.9.0/jquery.mask.min.js"></script>
  114.  
  115. </head>
  116. <body>
  117. <div style="margin:10px">
  118. <?php echo $out?>
  119. </div>
  120. </body>
  121. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement