Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cloudfaction/a1aafa3f079bdbf49f733bc9564749b0 to your computer and use it in GitHub Desktop.
Save cloudfaction/a1aafa3f079bdbf49f733bc9564749b0 to your computer and use it in GitHub Desktop.
<?php
// ------------ Sample showing how to use PHPGrid in Joomla 3.9.8 -------------
//
// Note: For this to work the following lines must be added to the
// Joomla index.php file before the line $app>execute();
//
// if (isset($_POST['id'])){
// unset($_REQUEST['id']);
// }
//
// This file is located in folder "phpgrid" off the Joomla root and
// the phpgrid "inc" and "js" folders are copied into "phpgrid".
//
// Use the Joomla extension "Sourcerer" from RegularLabs.com to execute
// http://download.regularlabs.com/?ext=sourcerer OR
// https://github.com/gridphp/joomla-sourcerer/raw/master/sourcerer-v7.5.0.zip
//
// In desired article, include grid code, e.g. demo.php using sourcerer syntax, (remove \ from require_once line)
// {source}
// <?php require_once JPATH_ROOT.'/phpgrid/demo.php'; ?\>
// {/source}
//
// ---------------------------------------------------------------------------
$db_conf = array();
$db_conf["type"] = 'mysqli';
$db_conf["server"] = $app->get("host");
$db_conf["user"] = $app->get("user");
$db_conf["password"] = $app->get("password");
$db_conf["database"] = $app->get("db");
// create the grid, passing the db connection array to the constructor
require_once(JPATH_ROOT."/phpgrid/inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);
$col = array();
$col["title"] = "Id";
$col["name"] = "id";
$col["hidden"] = false;
$cols[] = $col;
$col = array();
$col["title"] = "Gebruiker";
$col["name"] = "name";
$col["editable"] = true;
$col[“show”][“list”] = false;
$col[“show”][“view”] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Emailadres";
$col["name"] = "email";
$col["editable"] = true;
$cols[] = $col;
$col = array();
$col["title"] = "Datum regisitratie";
$col["name"] = "registerDate";
$col["editable"] = true;
$cols[] = $col;
// set a few parameters of the grid
$opts["caption"] = "Joomla Users";
// horizontal scroll bar
$opts["autowidth"] = true;
$opts["shrinkToFit"] = true;
$opt["export"] = array("format"=>"pdf", "filename"=>"my-file", "sheetname"=>"test");
$opt["export"] = array("filename"=>"my-file", "heading"=>"Invoice Details", "orientation"=>"landscape", "paper"=>"a4");
$g->set_options($opts);
$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export_excel"=>true, // export excel button
"export_pdf"=>true, // export pdf button
"export_csv"=>true, // export csv button
"export_html"=>false, // export html button
"autofilter" => true, // show/hide autofilter for search
"showhidecolumns" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);
// set database table for CRUD operations
$g->table = $app->get("dbprefix")."users";
$g->set_columns($cols);
// Make Joomla! send the css and js files that phpgrid depends upon
$doc->addStyleSheet( JURI::root( true ).'/phpgrid/js/themes/base/jquery-ui.custom.css' );
$doc->addStyleSheet( JURI::root( true ).'/phpgrid/js/jqgrid/css/ui.jqgrid.bs.css' );
// even though jquery.min.js this is inserted by Joomla we force it here to ensure jquery precedes jqgrid
$doc->addScript( JURI::root( true ).'/media/jui/js/jquery.min.js');
$doc->addScript( JURI::root( true ).'/phpgrid/js/jqgrid/js/i18n/grid.locale-en.js');
$doc->addScript( JURI::root( true ).'/phpgrid/js/jqgrid/js/jquery.jqGrid.min.js' );
$doc->addScript( JURI::root( true ).'/phpgrid/js/themes/jquery-ui.custom.min.js' );
// call render method to get the html and js output
$out = $g->render("users");
?>
<div>
<?php echo $out ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment