Created
July 23, 2020 06:12
-
-
Save dmsims/cee00e9f4d51463f1aeeb0ef73b5d198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP Grid Component | |
* | |
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org | |
* @version 2.0.0 | |
* @license: see license.txt included in package | |
*/ | |
// include db config | |
include_once("phpgrid/configremote.php"); | |
// include and create object | |
include(PHPGRID_LIBPATH."inc/jqgrid_dist.php"); | |
// Database config file to be passed in phpgrid constructor | |
$db_conf = array( | |
"type" => PHPGRID_DBTYPE, | |
"server" => PHPGRID_DBHOST, | |
"user" => PHPGRID_DBUSER, | |
"password" => PHPGRID_DBPASS, | |
"database" => PHPGRID_DBNAME | |
); | |
// passed from parent grid | |
$c_id = $_REQUEST["ownersid"]; | |
if (empty($c_id)) $c_id = 0; | |
$g = new jqgrid($db_conf); | |
$opt["caption"] = "Owners"; // caption of grid | |
$opt["responsive"] = true; | |
$opt ['toolbar'] = "bottom"; | |
$opt["sortname"] = 'Datebought'; | |
$opt["sortorder"] = "desc"; | |
$opt["height"] = "50%"; | |
$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" => false, // show/hide autofilter for search | |
"search" => "advance" // show single/multi field search condition (e.g. simple or advance) | |
) | |
); | |
$g->set_options($opt); | |
$g->table = "Owners"; | |
$g->select_command = "SELECT carsid, FirstName, LastName, Notes, Datebought, DateSold, Pistonheads, TVRCCID, Regno FROM Cars T1 INNER JOIN Owners T2 ON T1.id = T2.carsid WHERE T2.carsid = $c_id"; | |
$col = array(); | |
$col["title"] = "Primary key"; // caption of column, can use HTML tags too | |
$col["name"] = "OwnersPK"; // grid column name, same as db field or alias from sql | |
$col["width"] = "2"; // width on grid | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "carsid"; // caption of column, can use HTML tags too | |
$col["name"] = "carsid"; // grid column name, same as db field or alias from sql | |
$col["width"] = "2"; // width on grid | |
$col["editable"] = true; | |
$col["hidden"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "First"; // caption of column, can use HTML tags too | |
$col["name"] = "FirstName"; // grid column name, same as db field or alias from sql | |
$col["width"] = "10"; // width on grid | |
$col["editable"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Last"; // caption of column, can use HTML tags too | |
$col["name"] = "LastName"; // grid column name, same as db field or alias from sql | |
$col["width"] = "12"; // width on grid | |
$col["editable"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Regno"; // caption of column, can use HTML tags too | |
$col["name"] = "Regno"; // grid column name, same as db field or alias from sql | |
$col["width"] = "9"; // width on grid | |
$col["editable"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Notes"; // caption of column, can use HTML tags too | |
$col["name"] = "Notes"; // grid column name, same as db field or alias from sql | |
$col["width"] = "30"; // width on grid | |
$col["editable"] = true; | |
$col["formatter"] = "wysiwyg"; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Bought"; // caption of column, can use HTML tags too | |
$col["name"] = "Datebought"; // grid column name, same as db field or alias from sql | |
$col["width"] = "10"; // width on grid | |
$col["editable"] = true; | |
$col["formatter"] = "datetime"; // format as date | |
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'m/Y'); // http://docs.jquery.com/UI/Datepicker/formatDate | |
$cols[] = $col; | |
//$col = array(); | |
//$col["title"] = "Sold"; // caption of column, can use HTML tags too | |
//$col["name"] = "DateSold"; // grid column name, same as db field or alias from sql | |
//$col["width"] = "10"; // width on grid | |
//$col["editable"] = true; | |
//$col["formatter"] = "datetime"; // format as date | |
//$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'m/Y'); // http://docs.jquery.com/UI/Datepicker/formatDate | |
//$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Pistonheads"; // caption of column, can use HTML tags too | |
$col["name"] = "Pistonheads"; // grid column name, same as db field or alias from sql | |
$col["width"] = "14"; // width on grid | |
$col["editable"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "TVR CC"; // caption of column, can use HTML tags too | |
$col["name"] = "TVRCCID"; // grid column name, same as db field or alias from sql | |
$col["width"] = "12"; // width on grid | |
$col["editable"] = true; | |
$cols[] = $col; | |
// pass the cooked columns to grid | |
$g->set_columns($cols); | |
// generate grid output, with unique grid name as 'list1' | |
$out = $g->render("sub1"); | |
$cols = array(); | |
### GRID 2 ### | |
$g = new jqgrid($db_conf); | |
$opt = array(); | |
$opt["responsive"] = true; | |
$opt["caption"] = "Publications"; // caption of grid | |
$opt ['toolbar'] = "bottom"; | |
$opt["height"] = "50%"; | |
$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" => false, // show/hide autofilter for search | |
"search" => "advance" // show single/multi field search condition (e.g. simple or advance) | |
) | |
); | |
$g->set_options($opt); | |
$g->table = "Publications"; | |
// you can provide custom SQL query to display data | |
$g->select_command = "SELECT Carstomedia.BookID, Carstomedia.AssetID, Publications.Date, Publications.Publication, Publications.Scan FROM Cars INNER JOIN Carstomedia ON Cars.id = Carstomedia.AssetID INNER JOIN Publications ON Carstomedia.BookID = Publications.BookID WHERE Carstomedia.AssetID=$c_id"; | |
//$col = array(); | |
//$col["title"] = "PublicationsPK"; // caption of column, can use HTML tags too | |
//$col["name"] = "PublicationsPK"; // grid column name, same as db field or alias from sql | |
//$col["width"] = "2"; // width on grid | |
//$col["editable"] = true; | |
//$col["hidden"] = true; | |
//$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Date"; // caption of column, can use HTML tags too | |
$col["name"] = "Date"; // grid column name, same as db field or alias from sql | |
$col["width"] = "12"; // width on grid | |
$col["editable"] = true; | |
$col["formatter"] = "datetime"; // format as date | |
$col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y'); // http://docs.jquery.com/UI/Datepicker/formatDate | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Publication"; // caption of column, can use HTML tags too | |
$col["name"] = "Publication"; // grid column name, same as db field or alias from sql | |
$col["width"] = "25"; // width on grid | |
$col["editable"] = true; | |
$cols[] = $col; | |
$col = array(); | |
$col["title"] = "Link"; // caption of column, can use HTML tags too | |
$col["name"] = "Scan"; // grid column name, same as db field or alias from sql | |
$col["width"] = "12"; // width on grid | |
//$col["default"] = "<a href='http://google.com/?id={name}'>{name}</a>"; | |
$col["default"] = "<a href='http://www.theseacpages.co.uk/media/{Scan}'>{Scan}</a>"; | |
//$col["link"] = "http://www.theseacpages.co.uk/media/{Scan}"; | |
$col["editable"] = true; | |
$cols[] = $col; | |
# Custom made column to show link, must have default value as it's not db driven | |
$col = array(); | |
$col["title"] = "Google view"; | |
$col["name"] = "view_more"; | |
$col["width"] = "20"; | |
$col["align"] = "center"; | |
$col["sortable"] = false; | |
$col["link"] = "https://docs.google.com/viewer?url=http://www.theseacpages.co.uk/media/{Scan}"; // e.g. http://domain.com?id={id} given that, there is a column with $col["name"] = "id" exist | |
$col["linkoptions"] = "target='_blank'"; // extra params with <a> tag | |
$col["default"] = "Click to view"; // default link text | |
$cols[] = $col; | |
// pass the cooked columns to grid | |
$g->set_columns($cols); | |
$out2 = $g->render("sub2"); | |
echo "<div style='padding:5px;'>"; | |
echo "<fieldset>$out</fieldset>"; | |
echo "<fieldset>$out2</fieldset>"; | |
echo "</div>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment