This is a user contributed solution from user Per Holmes:
MODx wraps all session variables, meaning that the MODx session much be active for anything to appear in $_SESSION. This is a problem if the grid itself is loaded embedded in a MODx page, but the Ajax calls go directly to a script. Loading the session will make everything appear to be fine, but the session variables are empty.
The only way to restore the session that was originally created from within the MODx context is to place the following at the top of
phpGrid.php, after the 'use' statements:
require_once(MODX_CORE_PATH . 'model/modx/modx.class.php');
$modx= new modX();
../core/ path assume that the
/phpgrid/ is at the top level next to the index.php of MODx. Then it loads the MODx config and instantiates MODx, which reloads the session.
In order to invoke the grid, place the PHP script that creates the grid in e.g. /myassets/mygrid.php. If you load this file directly, it should produce a grid and nothing else.
Then in MODx create a Snippet call RunPHP with the following code:
And from within the page where you want the grid to appear, you call
Additionally, it's good to create a .htaccess file in /myassets/.htaccess, so that the grid can't be loaded directly, if e.g. access controls are used within MODx.
deny from all
allow from 127.0.0.1