Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample PHP Grid code to integrate in Joomla Article
<?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");
$grid = new jqgrid($db_conf);
// set a few parameters of the grid
$opts["caption"] = "Joomla Update Sites";
// horizontal scroll bar
$opts["autowidth"] = false;
$opts["shrinkToFit"] = false;
$grid->set_options($opts);
// set database table for CRUD operations
$grid->table = $app->get("dbprefix")."update_sites";
// Make Joomla! send the css and js files that phpgrid depends upon
$doc->addStyleSheet( JURI::root( true ).'/phpgrid/js/themes/redmond/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 = $grid->render("update_sites");
?>
<div>
<?php echo $out ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.