Skip to content

Instantly share code, notes, and snippets.

@mediac3
Created June 19, 2020 12:40
Show Gist options
  • Save mediac3/a17dff12bc28f7c6502ca5db23c3a815 to your computer and use it in GitHub Desktop.
Save mediac3/a17dff12bc28f7c6502ca5db23c3a815 to your computer and use it in GitHub Desktop.
/**
* 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'));
function script_footer(){
?>
<!-- if jquery already included in theme, comment very next line -->
<script src="https://mydomain/phpgrid/js/jquery.min.js" type="text/javascript"></script>
<script>var $ = jQuery.noConflict();</script>
<script src="https://mydomain/phpgrid/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="https://mydomain/phpgrid/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="https://mydomain/phpgrid/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
<?php
}
add_action('wp_footer', 'script_footer',20);
class phpgrid_users
{
public static function json()
{
// list1 is unique ID passed to render function on line 54
if ( (isset($_GET["grid_id"]) && $_GET["grid_id"]=="list1") && ($_SERVER["HTTP_X_REQUESTED_WITH"] == 'XMLHttpRequest' || isset($_GET["export"]) || isset($_GET["import"])))
{
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" => "localhost",
"user" => "-------------",
"password" => "----------------",
"database" => "-----------------"
);
$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 = "wpht_users";
// should be unique grid id
$out = $g->render("list1");
$base_url = get_option('siteurl');
?>
<link rel="stylesheet" type="text/css" media="screen" href="https://mydomain/phpgrid/js/themes/redmond/jquery-ui.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="https://mydomain/phpgrid/js/jqgrid/css/ui.jqgrid.bs.css" />
<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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment