Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress PHP Grid Framework Integration - Sample Snippet
/**
* PHP Grid Component
*
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 2.6.2
* @license: see license.txt included in package
*/
// Note: classname & grid-id should be unique when using multiple grids, line 18,23,57
// Same classname should be used in add_shortcode and add_action, line 13,16
// set your shortcode name, should be unique. array parameters are (classname,function)
add_shortcode("phpgrid-users", array('phpgrid_users','render'));
// ajax call management
add_action('template_redirect', array('phpgrid_users','json'));
// for datagrid in admin pages
add_action('admin_init', array('phpgrid_users','json'));
class phpgrid_users
{
public static function json()
{
// list1 is unique ID passed to render function on line 54
if ($_GET["grid_id"]=="list1" && $_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest')
{
self::render();
}
}
// actual grid sample code from demos
public static function render()
{
include_once(ABSPATH."phpgrid/inc/jqgrid_dist.php");
// Database config file to be passed in phpgrid constructor
$db_conf = array(
"type" => "mysqli",
"server" => DB_HOST,
"user" => DB_USER,
"password" => DB_PASSWORD,
"database" => DB_NAME
);
$g = new jqgrid($db_conf);
$opt["caption"] = "Sample Grid ". get_current_user_id();
// horizontal scroll bar
$opt["autowidth"] = false;
$opt["shrinkToFit"] = false;
$opt["cmTemplate"]["visible"] = "xs+";
$g->set_options($opt);
$g->table = "wp_users";
// should be unique grid id
$out = $g->render("list1");
$base_url = get_option('siteurl');
?>
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $base_url; ?>/phpgrid/js/themes/redmond/jquery-ui.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $base_url; ?>/phpgrid/js/jqgrid/css/ui.jqgrid.bs.css" />
<script src="<?php echo $base_url; ?>/phpgrid/js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo $base_url; ?>/phpgrid/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="<?php echo $base_url; ?>/phpgrid/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="<?php echo $base_url; ?>/phpgrid/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<style>
table {margin:0 !important; background-color: inherit;}
table td, table th {border:0px !important; text-align:inherit; background:inherit; }
.global-search input {padding: 3px 5px !important;}
.ui-jqgrid .ui-jqgrid-htable td, .ui-jqgrid .ui-jqgrid-htable th, .ui-jqgrid .ui-pg-table td {padding: 1px 1px 0 1px !important;}
.ui-jqgrid tr.jqgfirstrow td { padding: 0 2px 0 2px !important; }
</style>
<div>
<?php echo $out?>
</div>
<?php
}
}
/**
* PHP Grid Component
*
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 2.6.2
* @license: see license.txt included in package
*/
// set your shortcode name, should be unique
add_shortcode("phpgrid-users", 'phpgrid_render');
// ajax call management
add_action('template_redirect', 'phpgrid_json');
if (!defined("phpgrid_json"))
{
function phpgrid_json()
{
if ($_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest' )
{
phpgrid_render();
wp_die();
}
}
}
// actual grid sample code from demos
function phpgrid_render()
{
include_once(ABSPATH."phpgrid/inc/jqgrid_dist.php");
// Database config file to be passed in phpgrid constructor
$db_conf = array(
"type" => "mysqli",
"server" => DB_HOST,
"user" => DB_USER,
"password" => DB_PASSWORD,
"database" => DB_NAME
);
$g = new jqgrid($db_conf);
$opt["caption"] = "Sample Grid ". get_current_user_id();
// horizontal scroll bar
$opt["autowidth"] = false;
$opt["shrinkToFit"] = false;
$opt["cmTemplate"]["visible"] = "xs+";
$g->set_options($opt);
$g->table = "wp_users";
// should be unique grid id
$out = $g->render("list1");
$base_url = get_option('siteurl');
?>
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $base_url; ?>/phpgrid/js/themes/redmond/jquery-ui.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php echo $base_url; ?>/phpgrid/js/jqgrid/css/ui.jqgrid.bs.css" />
<script src="<?php echo $base_url; ?>/phpgrid/js/jquery.min.js" type="text/javascript"></script>
<script src="<?php echo $base_url; ?>/phpgrid/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="<?php echo $base_url; ?>/phpgrid/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="<?php echo $base_url; ?>/phpgrid/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<style>
table {margin:0 !important; background-color: inherit;}
table td, table th {border:0px !important; text-align:inherit; background:inherit; }
.global-search input {padding: 3px 5px !important;}
</style>
<div>
<?php echo $out?>
</div>
<?php
}
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.