Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * PHP Grid Component
- *
- * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
- * @version 1.5.2
- * @license: see license.txt included in package
- */
- // include db config
- include_once("../../config.php");
- // set up DB
- mysql_connect(PHPGRID_DBHOST, PHPGRID_DBUSER, PHPGRID_DBPASS);
- mysql_select_db(PHPGRID_DBNAME);
- // include and create object
- include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
- $g = new jqgrid();
- // this db table will be used for add,edit,delete
- $g->table = "clients";
- $col = array();
- $col["title"] = "Id";
- $col["name"] = "client_id";
- $col["width"] = "20";
- $col["editable"] = true;
- $col["hidden"] = true;
- $cols[] = $col;
- $col = array();
- $col["title"] = "Name";
- $col["name"] = "name";
- $col["editable"] = true;
- $col["width"] = "80";
- $col["edittype"] = "select"; // render as select
- # fetch data from database, with alias k for key, v for value
- $str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
- $col["editoptions"] = array(
- "value"=>$str,
- "onchange" => array(
- "sql"=>"select * from clients",
- "search_on"=>"client_id",
- "callback" => "fill_form" )
- );
- $col["stype"] = "select"; // enable dropdown search
- $col["searchoptions"] = array("value" => ":;".$str);
- $cols[] = $col;
- $col = array();
- $col["title"] = "Gender";
- $col["name"] = "gender";
- $col["width"] = "40";
- $col["editable"] = true;
- $cols[] = $col;
- $col = array();
- $col["title"] = "Company";
- $col["name"] = "company";
- $col["editable"] = true;
- $col["edittype"] = "textarea";
- $col["editoptions"] = array("rows"=>2, "cols"=>20);
- $cols[] = $col;
- // 2 dropdown columns to simulate multiple dependent dropdowns based on single dropdown (name)
- $col = array();
- $col["title"] = "Invoice";
- $col["name"] = "note";
- $col["width"] = "50";
- $col["editable"] = true;
- $col["edittype"] = "select"; // render as select
- $str = $g->get_dropdown_values("select note as k, note as v from invheader");
- $col["editoptions"] = array("value"=>$str);
- // initially load 'note' of that client_id
- $col["editoptions"]["onload"]["sql"] = "select note as k, note as v from invheader WHERE client_id = '{name}'";
- $col["formatter"] = "select"; // display label, not value
- $cols[] = $col;
- $col = array();
- $col["title"] = "Amount";
- $col["name"] = "amount";
- $col["width"] = "50";
- $col["search"] = true;
- $col["editable"] = true;
- $col["edittype"] = "select"; // render as select
- $str = $g->get_dropdown_values("select amount as k, amount as v from invheader");
- $col["editoptions"] = array("value"=>$str);
- // initially load 'note' of that client_id
- $col["editoptions"]["onload"]["sql"] = "select amount as k, amount as v from invheader WHERE client_id = '{name}'";
- $cols[] = $col;
- $g->set_columns($cols);
- $grid["caption"] = "Clients Data"; // caption of grid
- $grid["autowidth"] = true; // expand grid to screen width
- $grid["multiselect"] = false; // allow you to multi-select through checkboxes
- $g->set_options($grid);
- $g->set_actions(array(
- "add"=>true, // allow/disallow add
- "edit"=>true, // allow/disallow edit
- "delete"=>false, // allow/disallow delete
- "rowactions"=>true, // show/hide row wise edit/del/save option
- "autofilter" => true, // show/hide autofilter for search
- )
- );
- // generate grid output, with unique grid name as 'list1'
- $out = $g->render("list1");
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
- <html>
- <head>
- <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
- <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
- <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
- <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
- <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
- <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
- </head>
- <body>
- <div style="margin:10px">
- <?php echo $out?>
- </div>
- <script>
- function fill_form(data)
- {
- jQuery("input[name=gender].FormElement").val(data[0].gender);
- jQuery("textarea[name=company].FormElement").val(data[0].company);
- jQuery("input[name=gender].editable").val(data[0].gender);
- jQuery("textarea[name=company].editable").val(data[0].company);
- // fill dropdown 1 based on row data
- o = jQuery('select[name=note]').get();
- o.event = 'onload'; fx_get_dropdown(o,'note');
- // fill dropdown 2 based on row data
- o = jQuery('select[name=amount]').get();
- o.event = 'onload'; fx_get_dropdown(o,'amount');
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement