Skip to content

Instantly share code, notes, and snippets.

Last active June 14, 2020 19:57
What would you like to do?
Sample PHP Grid code to integrate in Joomla Article,
// ------------ 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 to execute
// OR
// 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
$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;
// 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/' );
// 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");
<?php echo $out ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment